Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows phone 8-通过Web表单发送推送通知,但不能通过电话发送推送通知_C#_Windows Phone 8_Push Notification - Fatal编程技术网

C# Windows phone 8-通过Web表单发送推送通知,但不能通过电话发送推送通知

C# Windows phone 8-通过Web表单发送推送通知,但不能通过电话发送推送通知,c#,windows-phone-8,push-notification,C#,Windows Phone 8,Push Notification,我制作了一个web服务,可以根据需要发送推送通知。当我从web表单调用该函数时,它工作得非常好。然而,当我从手机中调用相同的功能时,我根本没有收到通知,尽管响应是“已接收|活动|已连接”。功能如下: [WebMethod] public void SendNotification(string Title, string msg, string url) { try { string subscriptionUri = Ge

我制作了一个web服务,可以根据需要发送推送通知。当我从web表单调用该函数时,它工作得非常好。然而,当我从手机中调用相同的功能时,我根本没有收到通知,尽管响应是“已接收|活动|已连接”。功能如下:

[WebMethod]
    public void SendNotification(string Title, string msg, string url)
    {
        try
        {
            string subscriptionUri = GetNotificationUrl();

           HttpWebRequest sendNotificationRequest = (HttpWebRequest) WebRequest.Create(subscriptionUri);

            sendNotificationRequest.Method = "POST";

            string toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                                  "<wp:Notification xmlns:wp=\"WPNotification\">" +
                                  "<wp:Toast>" +
                                  "<wp:Text1>" + Title + "</wp:Text1>" +
                                  "<wp:Text2>" + msg + "</wp:Text2>" +
                                  "<wp:Param>" + url + "</wp:Param>" +
                                  "</wp:Toast></wp:Notification>";

            byte[] notificationMessage = Encoding.Default.GetBytes(toastMessage);

            // Set the web request content length.
            sendNotificationRequest.ContentLength = notificationMessage.Length;
            sendNotificationRequest.ContentType = "text/xml";
            sendNotificationRequest.Headers.Add("X-WindowsPhone-Target", "toast");
            sendNotificationRequest.Headers.Add("X-NotificationClass", "2");



            using (Stream requestStream = sendNotificationRequest.GetRequestStream())
            {
                requestStream.Write(notificationMessage, 0, notificationMessage.Length);
            }

            // Send the notification and get the response.

            HttpWebResponse response = (HttpWebResponse) sendNotificationRequest.GetResponse();
            string notificationStatus = response.Headers["X-NotificationStatus"];
            string notificationChannelStatus = response.Headers["X-SubscriptionStatus"];
            string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];

            WriteLog(notificationStatus + " | " + notificationChannelStatus + " | " +
                                              deviceConnectionStatus);
        }
        catch
        {


        }
    }
[WebMethod]
公共无效发送通知(字符串标题、字符串消息、字符串url)
{
尝试
{
字符串subscriptionUri=GetNotificationUrl();
HttpWebRequest sendNotificationRequest=(HttpWebRequest)WebRequest.Create(subscriptionUri);
sendNotificationRequest.Method=“POST”;
字符串toastMessage=“”+
"" +
"" +
“”+标题+“”+
“+msg+”+
“”+url+“”+
"";
byte[]notificationMessage=Encoding.Default.GetBytes(toastMessage);
//设置web请求内容长度。
sendNotificationRequest.ContentLength=notificationMessage.Length;
sendNotificationRequest.ContentType=“text/xml”;
sendNotificationRequest.Headers.Add(“X-WindowsPhone-Target”、“toast”);
sendNotificationRequest.Headers.Add(“X-NotificationClass”,“2”);
使用(Stream requestStream=sendNotificationRequest.GetRequestStream())
{
Write(notificationMessage,0,notificationMessage.Length);
}
//发送通知并获取响应。
HttpWebResponse=(HttpWebResponse)sendNotificationRequest.GetResponse();
字符串notificationStatus=response.Headers[“X-notificationStatus”];
字符串notificationChannelStatus=response.Headers[“X-SubscriptionStatus”];
字符串deviceConnectionStatus=response.Headers[“X-deviceConnectionStatus”];
WriteLog(notificationStatus+“|”+notificationChannelStatus+“|”+
设备连接状态);
}
接住
{
}
}

您是否试图让应用程序向自身发送通知?我认为应用程序处于活动状态时不会显示toast通知。你想做什么?不知道我怎么会忘记>>是的,你是对的,只要应用程序正在运行,你就不能收到通知,除非你处理了ShellToastNotificationReceived事件。我和一个朋友测试过,效果很好