我几乎要复制有关使用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;
}
}
}
任何有关我出错的指导都将非常感谢....
答案 0 :(得分:1)
从平台看,您似乎正在使用WindowsPhone。如果是这种情况,则必须创建MpnsRegistrationDescription。因此,您可能会收到异常,因为CHANnelURI不是WIndows Store CHannelURI。
让我知道,
埃利奥