views:

117

answers:

4

I am getting a web service response as below. It has additional XML tag and string tag in the response. I was not able to load this response into XMLDocument object in Dot Net. I have asked web service provider to remove those tags before sending response. But they said that this is the web service standard. Is it how web service suppose send the response?

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/"&gt;&lt;?xml version="1.0" encoding="UTF-8"?><?ACORD version="1.7.0"?>
<ACORD><InsuranceSvcRs></InsuranceSvcRs></ACORD></string>

Here is the code that calls web service

using (var webClient = new WebClient())
{
    webClient.Credentials = Credentials;
    byte[] responseArray;

    NameValueCollection postValues = GetParameters();
    responseArray = webClient.UploadValues(GetUploadURL(), "POST", postValues);
    responseString = Encoding.ASCII.GetString(responseArray);
}

Since I am using WebClient (not web service proxy), does web client class format the response like this?

EDIT: When I tried with sample HelloWorld webservice with the above code, I got the response like this

<?xml version=\"1.0\" encoding=\"utf-8\"?><string xmlns=\"http://tempuri.org/\"&gt;Hello World</string>

Having said that, I am repharasing my question Is it how webservice suppose send the response, when client proxy POST to the webservice?

+1  A: 

they said that this is the web service standard

All that I could recommend you is switching service provider :-)

If you don't, long and painful string manipulation is awaiting you unless your service provider doesn't provide you with an API capable of parsing this standard.

Darin Dimitrov
Since I am using WebClient (not web service proxy), does web client class format the response like this?
amz
The `WebClient` doesn't format responses. It sends HTTP requests to a web server.
Darin Dimitrov
A: 

Duplicated <?xml version="1.0" encoding="UTF-8"?>

If the service is giving you that answer, they have a bug.

  1. If you can, use another service.
  2. If you can't, you can always delete it from the XML and later process it.
cad
It's not a bug: probably, instead of building XML like every normal human would do, they concatenate a `<?xml version="1.0" encoding="UTF-8"?><?ACORD [...] ACORD>` with two other strings.
MainMa
@MainMa: that's a bug.
John Saunders
A: 

Hey guys thank you for all you responses. Since I am using the WebClient class to Post to thier webservice, response content does include "String" tag. But if I use web service proxy, .net does extract the content and remove the string tag for us. So the response is web service standard. When I tested with sample service I got the response like this

<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<string xmlns=\"http://tempuri.org/\"&gt;Hello World</string>

amz
You're wrong. .NET doesn't do any such thing. If you use the proxy, you're using SOAP, so you get a SOAP response. If you just POST, it's just XML.
John Saunders
Yes you are correct John. Thank you for clear explanation. I have put the SOAP response as above for HelloWorld web service.
amz
When I post, does service suppose to return the response like this "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<string xmlns=\"http://tempuri.org/\">Hello World</string>"?
amz
A: 

Yes you are correct John Saunders. .Net does nothing as I said in my earlier answer. Response itself different when I post versus use proxy.

When I use proxy I got response like this as a Soap<HttpResponse> <StatusCode>OK</StatusCode> <StatusDescription>OK</StatusDescription> <WebHeaders> <Content-Length>363</Content-Length> <Cache-Control>private, max-age=0</Cache-Control> <Content-Type>text/xml; charset=utf-8</Content-Type> <Date>Mon, 12 Jul 2010 20:01:17 GMT</Date> <Server>Microsoft-IIS/6.0</Server> <X-AspNet-Version>2.0.50727</X-AspNet-Version> <X-Powered-By>ASP.NET</X-Powered-By> </WebHeaders> </HttpResponse> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; <s:Header xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;/s:Header&gt; <soap:Body> <HelloWorldResponse xmlns="http://tempuri.org/"&gt; <HelloWorldResult>Hello World</HelloWorldResult> </HelloWorldResponse> </soap:Body> </soap:Envelope>

amz