我对Windows Phone 7设备的推送通知服务有疑问: 我现在可以发送推送通知,使用Web应用程序到电话,更改数据的瓷砖。但问题是:当我启动应用程序时,我需要在调试器输出中显示URI,然后将其复制粘贴到Web应用程序中,然后将该MPNS与适用于更新的MPNS联系一次一个电话。但我想创建一个可以自动进行多个调用的Web服务,检索应用程序的URI(在关闭并打开应用程序后发生更改,我认为),并向其发送推送通知。但我还没有找到一个MSDN主题来处理这个问题。他们只是使用赞扬,说:“以后需要用URI来替换。”所以我的问题是:如何使用手机将这样的消息发送给web服务,对其进行响应,然后再次连接到手机,处理此类请求? 还有:我是否需要经过身份验证的Web服务,还是有调试版本?发送从Windows Phone设备到webservice的推送通知
这是我迄今:
/// <summary>
/// Setup a connection with a webservice, in order to update a shell, either a toast- or a tile shell.
/// </summary>
/// <param name="shellType">The type of shell you wish to update</param>
public void SetupShellChannel (ShellBindType shellType)
{
//holds the push notification that is created. Since we can only have one notification channel open at any one time,
//we will need to check for existance. That is why, the channelName shouldn't be changed
HttpNotificationChannel _httpChannel = HttpNotificationChannel.Find(_channelName);
//if the _httpChannel was not found (read: does not exist)
if (_httpChannel == null)
{
_httpChannel = new HttpNotificationChannel(_channelName );
_httpChannel.Open();
//because there is more than one shelltype we can open, we will use a switch to call the method we seek
BindToShell(_httpChannel, shellType);
}
//Only one push notification service is allowed per application, so we cannot send a tile notification, as well as
//a toast message notification. When we attempt this, we get a InvalidOperationException
else
{
//in this case, the _httpChannel did already exist, but the problem is, we cannot just add the eventHandlers,
//because there is the danger that it didn't exist, and we would get a null pointer exception.
//_httpChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(httpChannel_ChannelUriUpdated);
//_httpChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(httpChannel_ErrorOccurred);
//For testing purposes, we now display the URI to the user, and as output. Normally, we would pass this URI back to the webserver
System.Diagnostics.Debug.WriteLine(_httpChannel.ChannelUri.ToString());
}
//if (_httpChannel.ChannelUri)
//When the URI is updated, we want this to be sent to the server as well, so we know that the adress has changed,
//and don't just send data somewhere into the void. Also, when encountering an error, we want to show the user when
//an error has occured.
_httpChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(HttpChannel_ChannelUriUpdated);
_httpChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(HttpChannel_ErrorOccurred);
}
//here, also we would return the URI to the server, but for debugging purposes, we display them to the user.
void HttpChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
MessageBox.Show(String.Format("the URI is {0}", e.ChannelUri.ToString()));
});
}
private void BindToShell(HttpNotificationChannel channel, ShellBindType shellType)
{
switch (shellType)
{
case ShellBindType.BindToShellTile:
channel.BindToShellTile();
break;
case ShellBindType.BindToShellToast:
channel.BindToShellToast();
break;
}
}
void HttpChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
{
//getting an error would be caugth here, and then displayed to the user.
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(String.Format("A push notification {0} error occured. {1}{(2)}{3}",
e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData));
});
}
您能否解释qn的第一部分 - 如何使用手机向web服务发送此类消息,作出响应并再次连接到手机,以处理此类请求。 – whihathac 2012-02-07 21:43:56