Answered by:
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();
}
}- Edited by Shakir Jahir John Tuesday, April 15, 2014 8:26 AM
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 "Mark as Answer" 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.- Marked as answer by Shakir Jahir John Friday, November 28, 2014 7:32 AM
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.
- Marked as answer by Anne Jing Monday, March 17, 2014 1:41 AM
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 "Mark as Answer" 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.- Marked as answer by Shakir Jahir John Friday, November 28, 2014 7:32 AM
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.
- Marked as answer by Anne Jing Monday, March 17, 2014 1:41 AM
Wednesday, March 5, 2014 5:47 PM