2つのWP7アプリを使用して、プッシュ通知機能を使用してメッセージを相互に送信しようとしているように聞こえます。あれは正しいですか?
サブスクリプションが成功したときに返送される一意のURIを使用して、プッシュ通知サービス(MSホスト)にサブスクライブするために、各デバイスが引き続き必要になることを理解しています。SL3 / 4はHttpWebRequestオブジェクトを作成できるため、送信する正しいパッケージを作成できるはずですが、投稿先のデバイスのURIを取得する方法が難しいと思います。通常、投稿はサブスクライバーに送信されます。サブスクライバーは、サブスクライブフェーズ中に返されたURIを認識しています。
私のWCFホストコードは、WCFがデバイスの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)がソケットをサポートすることを理解しています。これは、デバイスが通信するためのより適切な方法である可能性があります。
幸運を、
ジェイソン。