我必须在我的项目中实现推送通知。它有发送者(windows 手机窗口应用程序)、wcf 服务和客户端(windows 手机应用程序)。
如何替换发件人并使用我的 url 发送和接收来自客户端的通知?
我希望发件人是模拟器本身中的某个应用程序,它与客户端并行运行并将数据连续推送到客户端。
如何开发这样的应用程序
谁能告诉我的方式。
我必须在我的项目中实现推送通知。它有发送者(windows 手机窗口应用程序)、wcf 服务和客户端(windows 手机应用程序)。
如何替换发件人并使用我的 url 发送和接收来自客户端的通知?
我希望发件人是模拟器本身中的某个应用程序,它与客户端并行运行并将数据连续推送到客户端。
如何开发这样的应用程序
谁能告诉我的方式。
听起来好像您希望使用两个 WP7 应用程序使用推送通知功能来回发送消息。那是对的吗?
我的理解是,您仍然需要每台设备使用订阅成功时发回的唯一 URI 订阅推送通知服务(MS 托管)。似乎 SL3/4 可以创建 HttpWebRequest 对象,因此应该能够制定一个正确的包来发送,但是,在我看来,困难在于如何获取要将帖子发送到的设备的 URI。通常,帖子会发送给订阅者,订阅者知道它在 URI 上,因为它是在订阅阶段返回的。
我的 WCF 托管代码仅在 WCF 知道设备的 URI 时才有效,该设备的 URI 在调用 WCF 方法时发送:
public bool sendTileUpdate(string tileText, string url, string image)
{
string TilePushXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Tile>" +
"<wp:BackgroundImage>{2}</wp:BackgroundImage>" +
"<wp:Count>{0}</wp:Count>" +
"<wp:Title>{1}</wp:Title>" +
"</wp:Tile>" +
"</wp:Notification>";
try
{
HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(url);
sendNotificationRequest.Method = "POST";
sendNotificationRequest.Headers = new WebHeaderCollection();
sendNotificationRequest.ContentType = "text/xml";
// Tile
sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "token");
sendNotificationRequest.Headers.Add("X-NotificationClass", "1");
string str = string.Format(TilePushXML, "", tileText, image);
byte[] strBytes = new UTF8Encoding().GetBytes(str);
sendNotificationRequest.ContentLength = strBytes.Length;
using (Stream requestStream = sendNotificationRequest.GetRequestStream())
{
requestStream.Write(strBytes, 0, strBytes.Length);
}
HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse();
string notificationStatus = response.Headers["X-NotificationStatus"];
string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
return true;
}
catch (Exception e)
{
return false;
}
}
我知道这是一个 TileNotification,但原理是一样的。
我了解 Mango(WP7.1 和 SL4)将支持套接字,这可能是您的设备进行通信的更合适的方式!
祝你好运,
杰森。