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:
xml vb.net visual-studio deserialization xml-serialization
add a comment |
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:
xml vb.net visual-studio deserialization xml-serialization
add a comment |
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:
xml vb.net visual-studio deserialization xml-serialization
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:
xml vb.net visual-studio deserialization xml-serialization
xml vb.net visual-studio deserialization xml-serialization
asked Nov 8 at 16:55
Popo
1,67642143
1,67642143
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 9 at 20:21
Popo
1,67642143
1,67642143
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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