How to Deserialize SoapService's reponse message

A

Anbu

Hi All,

I need to Deserialize the SoapService's SoapEnvelope response object.

Here is the Body of the SoapEnvelope received as respone,
<q1:serviceResponse xmlns:q1="urn:CallSetup"><serviceReturn
xsi:type="q1:response"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance">ok</serviceReturn></q1:serviceResponse>


When i try to deserialize with the same class from the client, I'm
receiving the following error,
There is an error in XML document (1, 2).
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader, String encodingStyle, XmlDeserializationEvents events)
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Deserialize(Stream stream)

The source code is given below,
try
{
CS.response myObject;
XmlSerializer mySerializer = new
XmlSerializer(typeof(CS.response));

byte[] b =
System.Text.Encoding.Unicode.GetBytes(response.Body.InnerXml);
System.IO.MemoryStream ms = new MemoryStream(b);

myObject = (CS.response)mySerializer.Deserialize(ms);

}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);

}

This above function works fine, if the XML data is as serialized
<?xml version="1.0" encoding="utf-16"?><response>ok</response>

Is there any way to Deserialize the SoapEnvelope from the soapservice?
 
P

Pablo Cibraro [MVP]

Hi Anbu,

Are you using WSE ?. The Microsoft.Web.Services3.SoapEnvelope class has a
method to deserialize the body element.

CS.response myObject =
(CS.response)response.GetBodyObject(typeof(CS.response));

Regards,
Pablo Cibraro
http://weblogs.asp.net/cibrax
 
A

Anbu

Pablo,

Thanks for your reply. Unfortunately, it thows an error saying "There
is an error in the XML document".

Stack Trace:
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader, String encodingStyle, XmlDeserializationEvents events)\r\n
at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader, String encodingStyle)\r\n at
System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader
xmlReader)\r\n at
Microsoft.Web.Services3.SoapEnvelope.GetBodyObject(Type bodyType,
String defaultNamespace)\r\n at
Microsoft.Web.Services3.SoapEnvelope.GetBodyObject(Type bodyType)\r\n
at ....

But the soap envelope is as received from the web service. No changes
made. The return data type of the web service is an Enumerator.

Is there any other way to implement?

Thanks,
 
P

Pablo Cibraro [MVP]

So, the type you are using on the client is not the same as the type in the
response message. How did you do to generate the type on the client ? Are
you using the types created with the ws proxy ?.

Regards,
Pablo.
 
A

Anbu

Pablo,

Thanks for your follow-up.

Type of client is same as the server application's return type. Of
course, it's generated from the Webservice's wsdl file. But the web
service adds few namespaces in the response body. This causes the
problem.

To duplicate the same error, create a simple web service site like
HelloWorld, and see the description page of the method (not the WSDL).
There are two entries, one for Soap Post and another one for HTTP post.
The client application was able to recoganize the data if it's in HTTP
Post (response) format, but not Soap response's body.

I think XML deserialization can mainly used with the text files which
are serializable using the classes.

Any thoughts?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top