locked
Windows 8.1: consuming SOAP not working consistently

    Question

  • I am using below code to consume SOAP service in Windows 8.0 app its working fine but for windows 8.1 app the following code is not working consistently.

    What could be the issue in Windows 8.1? 

    private async Task<XDocument> SOAPCallService(string serviceUrl, string soapMessage, string soapAction)
            {
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(serviceUrl);
                req.Method = Constants.Method_POST;
                req.ContentType = Constants.ContentType;
                req.Accept = Constants.Accept;
                req.CookieContainer = this.cookieContainer;

                if (!string.IsNullOrEmpty(soapAction))
                {
                    req.Headers[Constants.Header_SOAP_Action] = soapAction;                
                }

                using (Stream stream = await req.GetRequestStreamAsync())
                {
                    using (StreamWriter writer = new StreamWriter(stream))
                    {
                        await writer.WriteAsync(soapMessage);
                    }
                    WebResponse response = await req.GetResponseAsync();                            
                }
                return XDocument.Load(response.GetResponseStream());

            }

    When I tried that I am getting "403 Forbidden" error as response. I need help to convert this code, so that it work on Windows 8.1.

    using (var client = new Windows.Web.Http.HttpClient())
                {
                    if (!string.IsNullOrEmpty(soapAction))
                    {
                        client.DefaultRequestHeaders.Add("SOAPAction", serviceUrl);
                    }
                    client.DefaultRequestHeaders.Add("User-Agent","Other");                
                    Windows.Web.Http.IHttpContent content = new Windows.Web.Http.HttpStringContent(soapMessage, Windows.Storage.Streams.UnicodeEncoding.Utf8, "text/xml");                
                    using (var response = await client.PostAsync(new Uri(serviceUrl), content))
                    {                   
                        var soapResponse = await response.Content.ReadAsStringAsync();                                        
                    }
                }


    Tuesday, March 4, 2014 4:02 PM

Answers

  • Hi,

    Would you enable "Private Networks (Client & Server)" or "Internet Network(Client &Server) in the manifest?

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, March 5, 2014 6:18 AM
  • Hi Anne,

    Yes it has been enabled, the issue is related to code. I managed to find out that we need to pass cookie to avoid "403 Forbidden" error. Looking how to pass cookie in HttpClient.

    Wednesday, March 5, 2014 5:47 PM

All replies

  • Hi,

    Would you enable "Private Networks (Client & Server)" or "Internet Network(Client &Server) in the manifest?

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, March 5, 2014 6:18 AM
  • Hi Anne,

    Yes it has been enabled, the issue is related to code. I managed to find out that we need to pass cookie to avoid "403 Forbidden" error. Looking how to pass cookie in HttpClient.

    Wednesday, March 5, 2014 5:47 PM