【发布时间】:2013-12-29 20:56:43
【问题描述】:
我几乎复制了这篇关于使用 Windows Azure 通知中心发送推送通知的文章:http://www.windowsazure.com/en-us/manage/services/notification-hubs/notify-users-aspnet/
不幸的是,当我尝试使用 CreateWindowsNativeRegistrationAsync 方法时,我遇到了 InvalidDataContractException 发生在 Microsoft.ServiceBus 中。我看不出我的代码与示例有任何区别,而且我没有进行序列化。 (大约在页面的一半处):
更新:在控制台应用程序中使用“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;
}
}
}
任何关于我哪里出错的指导将不胜感激......
【问题讨论】:
标签: c# asp.net azure azure-notificationhub