Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > How to Deserialize SoapService's reponse message

Reply
Thread Tools

How to Deserialize SoapService's reponse message

 
 
Anbu
Guest
Posts: n/a
 
      08-07-2006
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.Bod y.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?

 
Reply With Quote
 
 
 
 
Pablo Cibraro [MVP]
Guest
Posts: n/a
 
      08-07-2006
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.resp onse));

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


"Anbu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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.Bod y.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?
>



 
Reply With Quote
 
 
 
 
Anbu
Guest
Posts: n/a
 
      08-07-2006

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,

 
Reply With Quote
 
Pablo Cibraro [MVP]
Guest
Posts: n/a
 
      08-08-2006
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.

"Anbu" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ps.com...
>
> 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,
>



 
Reply With Quote
 
Anbu
Guest
Posts: n/a
 
      08-09-2006
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?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to Deserialize SoapService's reponse message Anbu ASP .Net 4 08-09-2006 11:02 AM
Re: client reponse ports for asp.net bruce barker ASP .Net 1 07-20-2004 08:00 PM
How to use Reponse.Redirect in ASP.NET Iin-line Code ? Simon Prince ASP .Net 1 07-14-2004 04:21 PM
ValidationSummary - error message in reponse to exception =?Utf-8?B?bWc=?= ASP .Net 1 04-05-2004 09:33 PM



Advertisments