How to Deserialize SoapService's reponse message

Discussion in 'ASP .Net' started by Anbu, Aug 7, 2006.

  1. Anbu

    Anbu Guest

    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?
    Anbu, Aug 7, 2006
    #1
    1. Advertising

  2. 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


    "Anbu" <> wrote in message
    news:...
    > 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?
    >
    Pablo Cibraro [MVP], Aug 7, 2006
    #2
    1. Advertising

  3. Anbu

    Anbu Guest

    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,
    Anbu, Aug 7, 2006
    #3
  4. 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" <> wrote in message
    news:...
    >
    > 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,
    >
    Pablo Cibraro [MVP], Aug 8, 2006
    #4
  5. Anbu

    Anbu Guest

    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?
    Anbu, Aug 9, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bWc=?=
    Replies:
    1
    Views:
    414
    Peter Blum
    Apr 5, 2004
  2. Ivan S
    Replies:
    0
    Views:
    532
    Ivan S
    Aug 13, 2008
  3. raj712k
    Replies:
    0
    Views:
    151
    raj712k
    Jun 16, 2004
  4. BenW

    WSEWSDL2.EXE for SoapService

    BenW, Jan 31, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    188
  5. Anbu

    How to Deserialize SoapService's reponse message

    Anbu, Aug 7, 2006, in forum: ASP .Net Web Services
    Replies:
    4
    Views:
    278
Loading...

Share This Page