2013-03-25 55 views
3

我们正试图测试推送通知,使用从文档的最新代码如何:设置为Windows Phone的WP7:推送通知通道URI是空

public HttpNotificationChannel myChannel; 
public void CreatingANotificationChannel() 
{ 
    myChannel = HttpNotificationChannel.Find("MyChannel"); 

    if (myChannel == null) 
    { 
    myChannel = new HttpNotificationChannel("MyChannel","www.contoso.com"); 

    // An application is expected to send its notification channel URI to its corresponding web service each time it launches. 
    // The notification channel URI is not guaranteed to be the same as the last time the application ran. 
    myChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(myChannel_ChannelUriUpdated); 

    myChannel.Open(); 
    } 
    else // Found an existing notification channel. 
    { 
    // The URI that the application sends to its web service. 
    Debug.WriteLine("Notification channel URI:" + myChannel.ChannelUri.ToString()); 
    } 

    myChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(myChannel_HttpNotificationReceived); 
    myChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(myChannel_ShellToastNotificationReceived); 
    myChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(myChannel_ErrorOccurred); 
} 

通知通道如果HttpNotificationChannel.Find()返回null,它会打开一个新频道,但ChannelUriUpdated事件从不触发。

如果HttpNotificationChannel.Find()返回一个通道,则ChannelUri属性为null。示例代码在这里崩溃,因为它假定ChannelUri属性不为null。

在任何情况下都不会触发ErrorOccurred事件。

我该如何解决这个问题?这个问题是由于微软服务器或其他东西?

Thnks提前

编辑 等待重播,十天后我很痛苦空URI问题 任何一个可以告诉我,我怎么能解决这个问题一段时间MSPN服务器给予chanalk URI ANS一些时间不是我的意思有些时候它给null引用异常。 微软在做什么?

+0

等待回复 – MansinhDodiya 2013-04-04 08:13:34

回答

1

如果我没有犯错,www.contoso.com这是一个示例URI来证明您需要放置您自己的服务器URL地址,但以我的经验,我从来没有以这种方式使用。我宁愿只是把

myChannel = new HttpNotificationChannel("MyChannel"); 

看看这个example(这是在西班牙),但代码是很清楚的,你需要做的设置推送通知客户端和服务内容。

我希望我帮你。

+0

thnanks重播,我使用同样喜欢这个myChannel = new HttpNotificationChannel(“MyChannel”);但没有工作一段时间uri fire null reffrence exception – MansinhDodiya 2013-04-02 11:11:36

0

你在什么移动正在测试的模拟器, 你有Windows Phone的开发的开发者帐户申购, 假如你开发者解锁您的手机,

Noorul。

+0

:我正在测试这个演示与移动和是的,我有开发者帐户,也是为了让你开发者解锁你的手机, – MansinhDodiya 2013-04-02 11:10:28

0

根据documentation,我认为问题在于您正在使用经过身份验证的Web服务的构造函数HttpNotificationChannel

相反,你应该使用只需要一个参数的构造函数,你可以在this example

/// Holds the push channel that is created or found. 
HttpNotificationChannel pushChannel; 

// The name of our push channel. 
string channelName = "ToastSampleChannel"; 

// Try to find the push channel. 
pushChannel = HttpNotificationChannel.Find(channelName); 

// If the channel was not found, then create a new connection to the push service. 
if (pushChannel == null) 
{ 
    pushChannel = new HttpNotificationChannel(channelName); 
    ... 
} 

检查希望它可以帮助