0

我想构建httpmessage发送推送通知(吐司类型),但它不能识别下面的代码中的方法。我在类库中有这个代码。无法构建HTTP消息推送通知在Windows Phone 7

在sendNotificationRequest.Headers.Add(“X-NotificationClass”,“2”)中添加方法;

sendNotificationRequest.ContentLength = notificationMessage.Length中的内容长度;

GetRequestStream在流requestStream = sendNotificationRequest.GetRequestStream()

的GetResponse在HttpWebResponse响应=(HttpWebResponse)sendNotificationRequest.GetResponse();

 HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(channel.ChannelUri.ToString()); 
     sendNotificationRequest.Method = "POST"; 
     //Indicate that you'll send toast notifications! 
     sendNotificationRequest.ContentType = "text/xml"; 
     sendNotificationRequest.Headers = new WebHeaderCollection(); 
     sendNotificationRequest.Headers.Add("X-NotificationClass", "2"); 
     if (string.IsNullOrEmpty(txtMessage.Text)) return; 

     //Create xml envelope 
     string data = "X-WindowsPhone-Target: toast\r\n\r\n" + 
       "<?xml version='1.0' encoding='utf-8'?>" + 
       "<wp:Notification xmlns:wp='WPNotification'>" + 
       "<wp:Toast>" + 
       "<wp:Text1>{0}</wp:Text1>" + 
       "</wp:Toast>" + 
       "</wp:Notification>"; 

     //Wrap custom data into envelope 
     string message = string.Format(data, txtMessage.Text); 
     byte[] notificationMessage = Encoding.Default.GetBytes(message); 

     // Set Content Length 
     sendNotificationRequest.ContentLength = notificationMessage.Length; 

     //Push data to stream 
     using (Stream requestStream = sendNotificationRequest.GetRequestStream()) 
     { 
      requestStream.Write(notificationMessage, 0, notificationMessage.Length); 
     } 

     //Get reponse for message sending 
     HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.GetResponse(); 
     string notificationStatus = response.Headers["X-NotificationStatus"]; 
     string notificationChannelStatus = response.Headers["X-SubscriptionStatus"]; 
     string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"]; 

回答

0

将代码移动到WCF项目后工作。