none
Unable to get the required output after deserialization in webservice RRS feed

  • Question

  • hi all,

    I am working on a WCF service where i need to deserialize an xml to a c# object.

    XML looks like this:

    <ns0:CUST_LOCK xmlns:ns0="http://BTS.Lock"><RESPONSE><LOCKSTATUS>123 - LOCKED</LOCKSTATUS><LOCKSTATUS>123 - LOCKED</LOCKSTATUS></RESPONSE></ns0:CUST_LOCK >

    But when i deserialize, it

                        

     using (var stringreader = new StringReader(secOrpara.objValue))
                    {

                    XmlSerializer xsxsr = new XmlSerializer(typeof(CUST_LOCK));
                        objReturn = (CUST_LOCK)xsxsr.Deserialize(stringreader);

    gives the response like this

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
       <s:Body>
          <II_MethodResponse xmlns="http://tempuri.org/">
             <II_MethodResponseResult xmlns:a="http://schemas.datacontract.org/2004/07/dbConnection.ITable" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <a:RESPONSE xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                   <b:string>21961581 - ALREADY LOCKED</b:string>
                   <b:string>21961579 - ALREADY LOCKED</b:string>
                   <b:string>22990436 - ALREADY LOCKED</b:string>
                   <b:string>22988607 - ALREADY LOCKED</b:string>
                   <b:string>22990186 - ALREADY LOCKED</b:string>
                   <b:string>22990205 - ALREADY LOCKED</b:string>
                   <b:string>22990238 - ALREADY LOCKED</b:string>
                   <b:string>23009130 - ALREADY LOCKED</b:string>
                 </a:RESPONSE>
             </II_MethodResponseResult>
          </II_MethodResponse>
       </s:Body>

    </s:Envelope>

    But i am expecting the result in this way, 

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
       <s:Body>
          <II_MethodResponse xmlns="http://tempuri.org/">
             <II_MethodResponseResult xmlns:a="http://schemas.datacontract.org/2004/07/dbConnection.ITable" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <a:RESPONSE xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                   <b:LOCKSTATUS>21961581 - ALREADY LOCKED</b:LOCKSTATUS>
                   <b:LOCKSTATUS>21961579 - ALREADY LOCKED</b:LOCKSTATUS>
                                </a:RESPONSE>
             </II_MethodResponseResult>
          </II_MethodResponse>
       </s:Body>

    </s:Envelope>

    Can you please suggest what can be done for this.


    • Edited by Veena H Thursday, January 18, 2018 6:03 AM ModifiedNamespace
    Wednesday, January 17, 2018 5:20 AM

All replies

  • Can anyone please help me :( 
    • Edited by Veena H Wednesday, January 17, 2018 9:51 AM Word added
    Wednesday, January 17, 2018 9:51 AM
  • Hi Veena,

    Could you share us a simple project which could reproduce your issue?

    It is not clear what is “secOrpara.objValue” and “CUST_LOCK”.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 18, 2018 2:02 AM
  • hi Tao,

    CUST_LOCK is the root node tag for the xml.  The xml is as below

    <ns0:CUST_LOCK xmlns:ns0="http://BTS.Lock">

    <RESPONSE>

    <LOCKSTATUS>123 - LOCKED</LOCKSTATUS>

    <LOCKSTATUS>123 - LOCKED</LOCKSTATUS>

    </RESPONSE>

    </ns0:CUST_LOCK >

    The converted class file looks like this:

    namespace dbConnection.Table
    {
        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://BTS.Lock")]
        [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://BTS.Lock", IsNullable = false)]
        public partial class CUST_LOCK
        {
            private string[] rESPONSEField;
            /// <remarks/>
            [System.Xml.Serialization.XmlArrayAttribute(Namespace = "")]
            [System.Xml.Serialization.XmlArrayItemAttribute("LOCKSTATUS", IsNullable = false)]
            public string[] RESPONSE
            {
                get{return this.rESPONSEField;}
                set{this.rESPONSEField = value;}
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
        [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
        public partial class RESPONSE
        {
            private LOCKSTATUS[] lOCKSTATUSField;
            /// <remarks/>
            [System.Xml.Serialization.XmlElementAttribute("LOCKSTATUS")]
            [XmlAttribute("LOCKSTATUS")]
            public LOCKSTATUS[] LOCKSTATUS
            {
           get{return this.lOCKSTATUSField;}
                set{this.lOCKSTATUSField = value;}
            }
        }
    }

    When I am trying to deserialize it to an object I used the below code

     using (var stringreader = new StringReader(secOrpara.objValue))
                    {

                    XmlSerializer xsxsr = new XmlSerializer(typeof(CUST_LOCK));
                        objReturn = (CUST_LOCK)xsxsr.Deserialize(stringreader); 

                     }

    Here secOrpara.objValue is the above xml mentioned.

    I am receiving the output as below


                 <a:RESPONSE xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                   <b:string>21961581 - ALREADY LOCKED</b:string>
                   <b:string>21961579 - ALREADY LOCKED</b:string>
                   </a:RESPONSE>
              

    But i am expecting the result in this way, 


                 <a:RESPONSE xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
                   <b:LOCKSTATUS>21961581 - ALREADY LOCKED</b:LOCKSTATUS>
                   <b:LOCKSTATUS>21961579 - ALREADY LOCKED</b:LOCKSTATUS>
                    </a:RESPONSE>

    Can you please help me in this regard.

    Thursday, January 18, 2018 6:02 AM
  • Hi Veena,

    I am a little confused about your expected result.

    For your code, it will de-serialize the xml to an object, which should be something like below.

    Why your expected result is xml? Could you share us how you get this wrong xml result?

    Do you mean you serialize it again?

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 19, 2018 7:27 AM
  • hi Tao,

    First I need to convert that to an object and have to map it with a webservice and then send it to the destination as an xml.

    There I am facing the issue as it is not going properly when I tested in SOAP UI.

    Thanks and Regards,

    Veena Handadi

    This is the code which I used where

    using (var stringreader = new StringReader(xml))
    {
    XmlSerializer xsxsr = new XmlSerializer(typeof(CUST_LOCK));
    objReturn = ((CUST_LOCK));)xsxsr.Deserialize(stringreader);
    }

    This method will go in a for loop and while coming to objReturn, it is becoming different than expected.

                   

    • Edited by Veena H Friday, January 19, 2018 9:10 AM Added xml
    Friday, January 19, 2018 9:05 AM
  • Hi Veena,

    >> First I need to convert that to an object and have to map it with a webservice and then send it to the destination as an xml.

    What is the expected object? Is the first image from my above reply correct?

    How did you map the object to a web service? And how did you send it as xml?

    >> I am facing the issue as it is not going properly when I tested in SOAP UI

    How did you test in SOAP UI? SOAP UI is a tool to send soap request, how did you send it with an object?

    >> This method will go in a for loop and while coming to objReturn, it is becoming different than expected.

    What is the expected result for objReturn? Note, objReturn is an object, if you mean it output xml result, please share us how you converted the object to xml.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 22, 2018 2:26 AM
  • Hi Tao,

    From the destination system (Oracle DB), we received a sample xml file, which is same as your first image. Using that i converted into a class with the help of xsd.exe. This format should be my output.

    My input is another xml, which i have to send to the Oracle DB in the form of input parameters.

    For that, I created another class to connect to the Oracle DB where i have to call a package with a stored procedure, by providing the input and output parameters. The output (its the same above sample xml) coming from the Oracle DB which we have to get as output.

    In this process, I have deserialized the output xml to an object and then created a webservice project where i am calling this created method (to connect to Oracle DB). When i run it i got the WSDL.

    I used it in the SOAP UI, and gave the input parameters to get the output value. 

    Kindly suggest if i have to deserialize the object to xml agian to get the required output?

    I am not so good in webservices so its a kind of confusion.

    Thanks and Regards,

    Veena 

    Monday, January 22, 2018 5:43 AM
  • I tried to use XDocument and assign it without deserializing the XML string. I can see that the data is coming to the required object as expected.

    But the WSDL is not loading when i debug the webservice. 

    I will update you once i get the output.

    Thanks, 

    Veena 

    Monday, January 22, 2018 9:01 AM
  • Hi Veena,

    >>I tried to use XDocument and assign it without deserializing the XML string. I can see that the data is coming to the required object as expected

    It seems your original issue related with deserializing has been resolved, if so, I would suggest you mark your reply as answer to close current thread.

    >>WSDL is not loading when i debug the webservice

    For this new issue, I would suggest you post a new thread, and share us how you load WSDL while debugging.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 23, 2018 1:56 AM
  • hi Tao, 

    Everything is related to same integration. Deserialization was not required for this. I had loaded the data into xml document type variable and returned as an xmlelement from the webservice. This is because, webservice cannot take the xml document type variable.

    The issue is resolved.

    Thanks and Regards,

    Veena

    Tuesday, January 23, 2018 3:35 AM