I am working on a project developed by a former employee. This project has a class that includes a function designed to accept an XML document and then parse the XML to locate attributes that match properties of the class, then return the class object populated with the property values.
Here is the XSD file, called PTSPodResult.xsd
?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://ift.tt/tphNwY">
<xs:element name="PTSPodResult">
<xs:complexType>
<xs:sequence>
<xs:element name="ResultText" type="xs:string" />
<xs:element name="ReturnCode" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Here is the class file, called PTSPodResultPartial.vb
Imports System.IO
Imports System.Xml.Serialization
Namespace TrackingObjects.V2.Rev1
Partial Public Class PTSPodResult
Shared Function Create(XmlString As String) As PTSPodResult
Dim sr As StringReader = New StringReader(XmlString.ToString())
Dim xsw As New XmlSerializer(GetType(PTSPodResult))
Dim returnResult As New PTSPodResult
Try
Dim PTSPodResultLoaded = xsw.Deserialize(sr)
returnResult = DirectCast(PTSPodResultLoaded, PTSPodResult)
Catch ex As Exception
Throw New Exception(XmlString)
End Try
Return returnResult
End Function
Friend Function ToXml() As String
Return XsdSerializer.ToXml(Me, Me.GetType, "PTSPodResult")
End Function
End Class
End Namespace
When I call the create method, passing it the outerXML from a webresponse, as soon as it hits the first line of the Create function, it returns with an exception. the ex.message value of the exception is the same text as the outerXML string I am passing to the function.
Listed below is a code snippet from the calling class;
Try
returnValue = TrackingObjects.V2.Rev1.PTSPodResult.Create(Response.OuterXml)
Catch ex As Exception
RaiseEvent ResponseError(ex.Message)
End Try
Return returnValue
The value of the Response.OuterXml is listed below;
<?xml version="1.0" encoding="UTF-8"?><PTSRRERESULT><ResultText>Your Proof of Delivery record is complete and will be processed shortly.</ResultText><ReturnCode>0</ReturnCode></PTSRRERESULT>
As soon as the Try section is executed, it immediately drops to the Catch section. The ex.Message value is listed below;
<?xml version="1.0" encoding="UTF-8"?><PTSRRERESULT><ResultText>Your Proof of Delivery record is complete and will be processed shortly.</ResultText><ReturnCode>0</ReturnCode></PTSRRERESULT>
As you can see, the excpetion message value is the save text as the response.outerXML I am sending to the TrackingObjects.V2.Rev1.PTSPodResult.Create() function.
My question is, why is the call to the TrackingObjects.V2.Rev1.PTSPodResult.Create() function immediately returning an exception? In the debugger, it is not even stepping into the function as I press F11. It is just returning back to the caller, throwing the exception.
Any ideas?
Thanks,
Dave
No comments:
Post a Comment