locked
Sending Toast returns Forbidden RRS feed

  • Question

  • I have setup a web service used for testing Push Notifications with a certificate supported for Windows Phone 7 from Root CA GeoTrust and upload to AppHub. I have tried adding both the cer and pfx certificate to the HttpWebRequest and keep getting the System.Net.WebException: The remote server returned an error: (403) Forbidden. The url returned is secure and the service name is set correctly, if set incorrectly I get unauthorized. Any help would be great!

     

    HttpWebRequest sendNotificationRequest = ( HttpWebRequest ) WebRequest . Create ( url );  
    sendNotificationRequest .Method = "POST";  
     
    string toastMessage = string . Empty;  
     
    toastMessage += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";  
    toastMessage += "<wp:Notification xmlns:wp=\"WPNotification\">";  
    toastMessage +=     "<wp:Toast>";  
    toastMessage +=         "<wp:Text1>" + title + "</wp:Text1>";  
    toastMessage +=         "<wp:Text2>" + message + "</wp:Text2>";  
    toastMessage +=     "</wp:Toast>";  
    toastMessage += "</wp:Notification>";  
     
     
    byte [ ] notificationMessage = Encoding . Default . GetBytes ( toastMessage );  
     
    sendNotificationRequest . ContentLength = notificationMessage . Length;  
    sendNotificationRequest . ContentType = "text/xml";  
     
    sendNotificationRequest . Headers . Add ( "X-WindowsPhone-Target" , "toast" );  
    sendNotificationRequest . Headers . Add ( "X-NotificationClass" , "2" );  
     
    //sendNotificationRequest . ClientCertificates . Add ( new System . Security . Cryptography . X509Certificates . X509Certificate ( Properties . Resources . ds ,"<password>") );  
    sendNotificationRequest . ClientCertificates . Add ( new System . Security . Cryptography . X509Certificates . X509Certificate ( Properties . Resources . ds ) );  
     
     
    using ( Stream requestStream = sendNotificationRequest . GetRequestStream ( ) )  
    {  
        requestStream . Write ( notificationMessage , 0 , notificationMessage . Length );  
    }  
     
    HttpWebResponse response = ( HttpWebResponse ) sendNotificationRequest . GetResponse ( );  
     
    string notificationStatus = response . Headers [ "X-NotificationStatus" ];  
    string notificationChannelStatus = response . Headers [ "X-SubscriptionStatus" ];  
    string deviceConnectionStatus = response . Headers [ "X-DeviceConnectionStatus" ]; 

     

     

     

     

     

     

    Sunday, March 11, 2012 12:30 AM

All replies

  • there's nothing wrong with the code.  you need to add the .cer to the request.  are you running the code on the domain that the certificate is registered with?
    Monday, March 12, 2012 3:27 AM
  • Hi,

    Thanks for your reply.

    Yes I have attached the certificate, I have tried both PFX and CER to no joy. I have even bound the request to the external IP that the domain is registered on. The only other thing is that I am not using port 443 but another port number.

    sendNotificationRequest . ClientCertificates . Add ( new System . Security . Cryptography . X509Certificates . X509Certificate ( Properties . Resources . ds ) );


    From above I have added the certificate that has been embedded as a resource and the application's pool has been given read access to the private keys. I have even included the certificate chain in the PFX. I have tried debugging the request using fiddler and Microsoft Network Monitor.
    Monday, March 12, 2012 11:37 AM
  • Just an update, I have resolved this issue by providing the port number in the service name:

    new HttpNotificationChannel ( "TestChannel" , "www.example.com:1567" ); 
    Monday, March 12, 2012 2:03 PM
  • You may want to check if you are truly using the authenticated service.  I've been fighting a similar issue except using PHP and when I tried your solution I found that the URI had been changed to throttled (meaning non-authenticated notifications).
    Tuesday, March 13, 2012 12:57 AM
  • Yes your right! Thanks, back to the drawing board lol

    Would be good if someone could advice how to configure IIS for mutual authentication or even comment on this part, every thing else looks ok
    Tuesday, March 13, 2012 1:17 AM