我几乎复制了这篇关于使用 Windows Azure 通知中心发送推送通知的文章:http: //www.windowsazure.com/en-us/manage/services/notification-hubs/notify-users-aspnet/
不幸的是,当我尝试使用CreateWindowsNativeRegistrationAsync方法时,我遇到了 Microsoft.ServiceBus 中发生的 InvalidDataContractException 。我看不出我的代码与示例有任何区别,而且我没有进行序列化。(大约在页面的一半处):
更新:将相同的代码放在带有“ http://test.com ”作为channelURI的控制台应用程序中会导致异常和以下错误:“不支持的通道uri:http ://test.com ”
public async Task<bool> NotificationRegistration(User user, NotificationRegistration reg)
{
var regs = await hubClient.GetRegistrationsByTagAsync(reg.InstallationID, 100);
bool updated = false;
bool firstRegistration = true;
RegistrationDescription registration = null;
foreach (var regDescription in regs)
{
if (firstRegistration)
{
regDescription.Tags = new HashSet<string>() { reg.InstallationID, user._id };
// We need to handle each platform separately.
switch (reg.Platform)
{
case "WP":
var winReg = regDescription as WindowsRegistrationDescription;
winReg.ChannelUri = new Uri(reg.ChannelUri);
registration = await hubClient.UpdateRegistrationAsync(winReg);
break;
}
updated = true;
firstRegistration = false;
}
else
{
// We shouldn't have any extra registrations; delete if we do.
await hubClient.DeleteRegistrationAsync(regDescription);
}
}
// Create a new registration.
if (!updated)
{
switch (reg.Platform)
{
case "WP":
//always fails here
registration = await hubClient.CreateWindowsNativeRegistrationAsync(reg.ChannelUri, new string [] { reg.InstallationID, user._id });
break;
}
}
}
任何关于我哪里出错的指导将不胜感激......