I'm having difficulties deserializing XML from a SOAP request to an object.
The XML looks like this (part of it), can be altered, slightly, if necessary:
<v001:OrderRequest xmlns:v001="http://ift.tt/1tvvfjq">
<v001:TheOrder>
...
</v001:TheOrder>
</v001:OrderRequest>
This is the class (again, part of it), can not be changed:
...
<System.Diagnostics.DebuggerStepThroughAttribute(), _
System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"), _
System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced), _
System.ServiceModel.MessageContractAttribute(WrapperName:="OrderRequest", WrapperNamespace:="http://ift.tt/1tvvfjq", IsWrapped:=true)> _
Partial Public Class OrderRequest
<System.ServiceModel.MessageBodyMemberAttribute([Namespace]:="http://ift.tt/1tvvfjq", Order:=0)> _
Public TheOrder As Service.TheOrder
Public Sub New()
MyBase.New
End Sub
Public Sub New(ByVal TheOrder As Service.Order)
MyBase.New
Me.TheOrder = TheOrder
End Sub
End Class
...
And this is the code I use to deserialize:
...
Dim xmlString As String = requestEnvelope.Body.InnerXml
Dim orderRequest As Service.OrderRequest = Nothing
Using xmlTextReader As New XmlTextReader(New MemoryStream(xmlString))
Dim xmlSerializer As New XmlSerializer(GetType(Service.OrderRequest), New XmlRootAttribute("OrderRequest"))
orderRequest = CType(xmlSerializer.Deserialize(xmlTextReader), Service.OrderRequest)
End Using
...
But I keep getting the following error:
There is an error in XML document (1, 2).
<OrderRequest xmlns='http://ift.tt/1tvvfjq'> was not expected.
I've tried stripping namespaces, prefixes, omitting the XmlRootAttribute parameter for the XmlSerializer, ... resulting in different error messages... Is there something I'm missing or doing wrong? I've been staring at this for almost 2 days now and I fear I'm just overlooking something.
No comments:
Post a Comment