Question

I'm pretty much copying this article about using the Windows Azure Notification Hub to send push notifications: http://www.windowsazure.com/en-us/manage/services/notification-hubs/notify-users-aspnet/

Unfortunately, I'm running into an InvalidDataContractException occurring in Microsoft.ServiceBus when I try to use the CreateWindowsNativeRegistrationAsync method. I can't see any difference in my code from the example and I'm not doing an serialisation. (about half way down the page):

UPDATE: Putting the same code in a console app with "http://test.com" as the channelURI causes an exception and the following error: "Unsupported channel 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;
    }
  }
}

Any guidance as to where I'm going wrong would be greatly appreciated....

Was it helpful?

Solution

From the platform it seems you are using WindowsPhone. If that is the case you have to create an MpnsRegistrationDescription. So you might be getting an exception because the CHannelURI is not a WIndows Store CHannelURI.

Let me know,

Elio

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top