[英]InvalidDataContractException using Azure Notification Hub
我正在復制有關使用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;
}
}
}
關於我要去哪里的任何指導將不勝感激....
從平台上看,您似乎正在使用WindowsPhone。 如果是這種情況,則必須創建一個MpnsRegistrationDescription。 因此,由於CHannelURI不是Windows商店CHannelURI,因此您可能會遇到異常。
讓我知道,
埃利奧
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.