Trouble Deserializing XML into Object properties end up null











up vote
1
down vote

favorite












I am working on a handling a response from a SOAP web service call. When the method in the client object tries to deserialize the response, it is nothing.



I have set up a test to emulate the deserialization process, but still cannot get the values for IsSuccess and Message to populate in the object.



Please help me out here to determine what is missing, so the deserialization process will completely deserialize the xml into the corresponding object. The contract code is auto generated using svcutil.



EDIT: I can manipulate the xml as needed with a messageinspector, so if the issue is with the xml I just need to figure out what to change.



Contract clases:



<System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440"),
System.SerializableAttribute(),
System.Diagnostics.DebuggerStepThroughAttribute(),
System.ComponentModel.DesignerCategoryAttribute("code"),
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="Green:EggsandHam.wsdll")>
Partial Public Class NumberResponse

Private isSuccessField As String

Private messageField As String

'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(Order:=0)>
Public Property IsSuccess() As String
Get
Return Me.isSuccessField
End Get
Set(value As String)
Me.isSuccessField = value
End Set
End Property

'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(Order:=1)>
Public Property Message() As String
Get
Return Me.messageField
End Get
Set(value As String)
Me.messageField = value
End Set
End Property
End Class


<System.Diagnostics.DebuggerStepThroughAttribute(),
System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"),
System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced),
System.ServiceModel.MessageContractAttribute(IsWrapped:=False)>
Partial Public Class NumberResponse1

<System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="Green:EggsandHam.wsdl", Order:=0)>
Public NumberResponse As NumberResponse

Public Sub New()
MyBase.New()
End Sub

Public Sub New(ByVal NumberResponse As NumberResponse)
MyBase.New()
Me.NumberResponse = NumberResponse
End Sub
End Class


Test:



Imports System.IO
Imports System.Text
Imports System.Xml.Serialization

Module Module1

Sub Main()
Dim u As New NumberResponse1()
u = Deserialize(Of NumberResponse1)(XElement.Load("C:testnumber.xml"))
Console.WriteLine(u.NumberResponse.Message)
End Sub

Public Function Deserialize(Of T)(ByVal xElement As XElement) As T
Using memoryStream As New MemoryStream(Encoding.ASCII.GetBytes(xElement.ToString()))
Dim xmlSerializer As New XmlSerializer(GetType(T))
Return xmlSerializer.Deserialize(memoryStream)
End Using
End Function

End Module


XML:



<?xml version="1.0" encoding="utf-8"?>
<NumberResponse1>
<NumberResponse>
<ns1:NumberResponse xmlns:ns1="Green:EggsandHam.wsdl">
<ns1:IsSuccess>true</ns1:IsSuccess>
<ns1:Message>number processed successfully.</ns1:Message>
</ns1:NumberResponse>
</NumberResponse>
</NumberResponse1>


Output:



enter image description here










share|improve this question


























    up vote
    1
    down vote

    favorite












    I am working on a handling a response from a SOAP web service call. When the method in the client object tries to deserialize the response, it is nothing.



    I have set up a test to emulate the deserialization process, but still cannot get the values for IsSuccess and Message to populate in the object.



    Please help me out here to determine what is missing, so the deserialization process will completely deserialize the xml into the corresponding object. The contract code is auto generated using svcutil.



    EDIT: I can manipulate the xml as needed with a messageinspector, so if the issue is with the xml I just need to figure out what to change.



    Contract clases:



    <System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440"),
    System.SerializableAttribute(),
    System.Diagnostics.DebuggerStepThroughAttribute(),
    System.ComponentModel.DesignerCategoryAttribute("code"),
    System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="Green:EggsandHam.wsdll")>
    Partial Public Class NumberResponse

    Private isSuccessField As String

    Private messageField As String

    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute(Order:=0)>
    Public Property IsSuccess() As String
    Get
    Return Me.isSuccessField
    End Get
    Set(value As String)
    Me.isSuccessField = value
    End Set
    End Property

    '''<remarks/>
    <System.Xml.Serialization.XmlElementAttribute(Order:=1)>
    Public Property Message() As String
    Get
    Return Me.messageField
    End Get
    Set(value As String)
    Me.messageField = value
    End Set
    End Property
    End Class


    <System.Diagnostics.DebuggerStepThroughAttribute(),
    System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"),
    System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced),
    System.ServiceModel.MessageContractAttribute(IsWrapped:=False)>
    Partial Public Class NumberResponse1

    <System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="Green:EggsandHam.wsdl", Order:=0)>
    Public NumberResponse As NumberResponse

    Public Sub New()
    MyBase.New()
    End Sub

    Public Sub New(ByVal NumberResponse As NumberResponse)
    MyBase.New()
    Me.NumberResponse = NumberResponse
    End Sub
    End Class


    Test:



    Imports System.IO
    Imports System.Text
    Imports System.Xml.Serialization

    Module Module1

    Sub Main()
    Dim u As New NumberResponse1()
    u = Deserialize(Of NumberResponse1)(XElement.Load("C:testnumber.xml"))
    Console.WriteLine(u.NumberResponse.Message)
    End Sub

    Public Function Deserialize(Of T)(ByVal xElement As XElement) As T
    Using memoryStream As New MemoryStream(Encoding.ASCII.GetBytes(xElement.ToString()))
    Dim xmlSerializer As New XmlSerializer(GetType(T))
    Return xmlSerializer.Deserialize(memoryStream)
    End Using
    End Function

    End Module


    XML:



    <?xml version="1.0" encoding="utf-8"?>
    <NumberResponse1>
    <NumberResponse>
    <ns1:NumberResponse xmlns:ns1="Green:EggsandHam.wsdl">
    <ns1:IsSuccess>true</ns1:IsSuccess>
    <ns1:Message>number processed successfully.</ns1:Message>
    </ns1:NumberResponse>
    </NumberResponse>
    </NumberResponse1>


    Output:



    enter image description here










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am working on a handling a response from a SOAP web service call. When the method in the client object tries to deserialize the response, it is nothing.



      I have set up a test to emulate the deserialization process, but still cannot get the values for IsSuccess and Message to populate in the object.



      Please help me out here to determine what is missing, so the deserialization process will completely deserialize the xml into the corresponding object. The contract code is auto generated using svcutil.



      EDIT: I can manipulate the xml as needed with a messageinspector, so if the issue is with the xml I just need to figure out what to change.



      Contract clases:



      <System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440"),
      System.SerializableAttribute(),
      System.Diagnostics.DebuggerStepThroughAttribute(),
      System.ComponentModel.DesignerCategoryAttribute("code"),
      System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="Green:EggsandHam.wsdll")>
      Partial Public Class NumberResponse

      Private isSuccessField As String

      Private messageField As String

      '''<remarks/>
      <System.Xml.Serialization.XmlElementAttribute(Order:=0)>
      Public Property IsSuccess() As String
      Get
      Return Me.isSuccessField
      End Get
      Set(value As String)
      Me.isSuccessField = value
      End Set
      End Property

      '''<remarks/>
      <System.Xml.Serialization.XmlElementAttribute(Order:=1)>
      Public Property Message() As String
      Get
      Return Me.messageField
      End Get
      Set(value As String)
      Me.messageField = value
      End Set
      End Property
      End Class


      <System.Diagnostics.DebuggerStepThroughAttribute(),
      System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"),
      System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced),
      System.ServiceModel.MessageContractAttribute(IsWrapped:=False)>
      Partial Public Class NumberResponse1

      <System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="Green:EggsandHam.wsdl", Order:=0)>
      Public NumberResponse As NumberResponse

      Public Sub New()
      MyBase.New()
      End Sub

      Public Sub New(ByVal NumberResponse As NumberResponse)
      MyBase.New()
      Me.NumberResponse = NumberResponse
      End Sub
      End Class


      Test:



      Imports System.IO
      Imports System.Text
      Imports System.Xml.Serialization

      Module Module1

      Sub Main()
      Dim u As New NumberResponse1()
      u = Deserialize(Of NumberResponse1)(XElement.Load("C:testnumber.xml"))
      Console.WriteLine(u.NumberResponse.Message)
      End Sub

      Public Function Deserialize(Of T)(ByVal xElement As XElement) As T
      Using memoryStream As New MemoryStream(Encoding.ASCII.GetBytes(xElement.ToString()))
      Dim xmlSerializer As New XmlSerializer(GetType(T))
      Return xmlSerializer.Deserialize(memoryStream)
      End Using
      End Function

      End Module


      XML:



      <?xml version="1.0" encoding="utf-8"?>
      <NumberResponse1>
      <NumberResponse>
      <ns1:NumberResponse xmlns:ns1="Green:EggsandHam.wsdl">
      <ns1:IsSuccess>true</ns1:IsSuccess>
      <ns1:Message>number processed successfully.</ns1:Message>
      </ns1:NumberResponse>
      </NumberResponse>
      </NumberResponse1>


      Output:



      enter image description here










      share|improve this question













      I am working on a handling a response from a SOAP web service call. When the method in the client object tries to deserialize the response, it is nothing.



      I have set up a test to emulate the deserialization process, but still cannot get the values for IsSuccess and Message to populate in the object.



      Please help me out here to determine what is missing, so the deserialization process will completely deserialize the xml into the corresponding object. The contract code is auto generated using svcutil.



      EDIT: I can manipulate the xml as needed with a messageinspector, so if the issue is with the xml I just need to figure out what to change.



      Contract clases:



      <System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440"),
      System.SerializableAttribute(),
      System.Diagnostics.DebuggerStepThroughAttribute(),
      System.ComponentModel.DesignerCategoryAttribute("code"),
      System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True, [Namespace]:="Green:EggsandHam.wsdll")>
      Partial Public Class NumberResponse

      Private isSuccessField As String

      Private messageField As String

      '''<remarks/>
      <System.Xml.Serialization.XmlElementAttribute(Order:=0)>
      Public Property IsSuccess() As String
      Get
      Return Me.isSuccessField
      End Get
      Set(value As String)
      Me.isSuccessField = value
      End Set
      End Property

      '''<remarks/>
      <System.Xml.Serialization.XmlElementAttribute(Order:=1)>
      Public Property Message() As String
      Get
      Return Me.messageField
      End Get
      Set(value As String)
      Me.messageField = value
      End Set
      End Property
      End Class


      <System.Diagnostics.DebuggerStepThroughAttribute(),
      System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"),
      System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced),
      System.ServiceModel.MessageContractAttribute(IsWrapped:=False)>
      Partial Public Class NumberResponse1

      <System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="Green:EggsandHam.wsdl", Order:=0)>
      Public NumberResponse As NumberResponse

      Public Sub New()
      MyBase.New()
      End Sub

      Public Sub New(ByVal NumberResponse As NumberResponse)
      MyBase.New()
      Me.NumberResponse = NumberResponse
      End Sub
      End Class


      Test:



      Imports System.IO
      Imports System.Text
      Imports System.Xml.Serialization

      Module Module1

      Sub Main()
      Dim u As New NumberResponse1()
      u = Deserialize(Of NumberResponse1)(XElement.Load("C:testnumber.xml"))
      Console.WriteLine(u.NumberResponse.Message)
      End Sub

      Public Function Deserialize(Of T)(ByVal xElement As XElement) As T
      Using memoryStream As New MemoryStream(Encoding.ASCII.GetBytes(xElement.ToString()))
      Dim xmlSerializer As New XmlSerializer(GetType(T))
      Return xmlSerializer.Deserialize(memoryStream)
      End Using
      End Function

      End Module


      XML:



      <?xml version="1.0" encoding="utf-8"?>
      <NumberResponse1>
      <NumberResponse>
      <ns1:NumberResponse xmlns:ns1="Green:EggsandHam.wsdl">
      <ns1:IsSuccess>true</ns1:IsSuccess>
      <ns1:Message>number processed successfully.</ns1:Message>
      </ns1:NumberResponse>
      </NumberResponse>
      </NumberResponse1>


      Output:



      enter image description here







      xml vb.net visual-studio deserialization xml-serialization






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 8 at 16:55









      Popo

      1,67642143




      1,67642143
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          I figured out the issue by reverse engineering, I serialized the classes to xml. The new xml ended up looking like so:



          <?xml version="1.0" encoding="utf-8"?>
          <NumberResponse1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <NumberResponse>
          <IsSuccess xmlns="Green:EggsandHam.wsdl">True</IsSuccess>
          <Message xmlns="Green:EggsandHam.wsdl">your father smelt of elderberries</Message>
          </NumberResponse>
          </NumberResponse1>


          It was missing the xmlschema namespaces.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53212555%2ftrouble-deserializing-xml-into-object-properties-end-up-null%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            I figured out the issue by reverse engineering, I serialized the classes to xml. The new xml ended up looking like so:



            <?xml version="1.0" encoding="utf-8"?>
            <NumberResponse1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <NumberResponse>
            <IsSuccess xmlns="Green:EggsandHam.wsdl">True</IsSuccess>
            <Message xmlns="Green:EggsandHam.wsdl">your father smelt of elderberries</Message>
            </NumberResponse>
            </NumberResponse1>


            It was missing the xmlschema namespaces.






            share|improve this answer

























              up vote
              0
              down vote



              accepted










              I figured out the issue by reverse engineering, I serialized the classes to xml. The new xml ended up looking like so:



              <?xml version="1.0" encoding="utf-8"?>
              <NumberResponse1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
              <NumberResponse>
              <IsSuccess xmlns="Green:EggsandHam.wsdl">True</IsSuccess>
              <Message xmlns="Green:EggsandHam.wsdl">your father smelt of elderberries</Message>
              </NumberResponse>
              </NumberResponse1>


              It was missing the xmlschema namespaces.






              share|improve this answer























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                I figured out the issue by reverse engineering, I serialized the classes to xml. The new xml ended up looking like so:



                <?xml version="1.0" encoding="utf-8"?>
                <NumberResponse1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                <NumberResponse>
                <IsSuccess xmlns="Green:EggsandHam.wsdl">True</IsSuccess>
                <Message xmlns="Green:EggsandHam.wsdl">your father smelt of elderberries</Message>
                </NumberResponse>
                </NumberResponse1>


                It was missing the xmlschema namespaces.






                share|improve this answer












                I figured out the issue by reverse engineering, I serialized the classes to xml. The new xml ended up looking like so:



                <?xml version="1.0" encoding="utf-8"?>
                <NumberResponse1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                <NumberResponse>
                <IsSuccess xmlns="Green:EggsandHam.wsdl">True</IsSuccess>
                <Message xmlns="Green:EggsandHam.wsdl">your father smelt of elderberries</Message>
                </NumberResponse>
                </NumberResponse1>


                It was missing the xmlschema namespaces.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 20:21









                Popo

                1,67642143




                1,67642143






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53212555%2ftrouble-deserializing-xml-into-object-properties-end-up-null%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Schultheiß

                    Liste der Kulturdenkmale in Wilsdruff

                    Android Play Services Check