Question

Consider a .NET client calling into a remote XML SOAP web service that's defined as a Web Reference. The client calls the service, and is attempting to deserialize the return XML into an object.

The web method is executing properly, and the XML returned from the service is well formed, confirmed in Fiddler. The web service is a known good working service, as we have another client (.NET 2.0) consuming it without issue.

When the .NET web service proxy classes attempt to deserialize the returned XML, this error is thrown:

System.InvalidOperationException: There is an error in XML document (1, 1999). ---> System.Xml.XmlException: 'EndElement' is an invalid XmlNodeType. Line 1, position 1999. at System.Xml.XmlReader.ReadStartElement()
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader_PRPA_AR101202_Service.Read135_MCCI_MT000200LocatedEntity(Boolean isNullable, Boolean checkType)

The line/column (1,1999) of the XML response that it's complaining about is the / in </device>:

<sender>
   <device>
      ..snip..
      <location classCode="IDENT" realmCode="xyz" />
   </device>

How can I resolve this issue with .NET deserialization?

Attempted solutions with no resolution / more information:

Was it helpful?

Solution 2

I used a .config tweak to force the XML serializer to use legacy behaviour:

<configuration>
     <system.xml.serialization> 
        <xmlSerializer  useLegacySerializerGeneration="true" />    
     </system.xml.serialization>
</configuration>

Serialization or deserialization failures when you run existing XML serialization code in WCF 4.5

OTHER TIPS

The second line of the stacktrace suggests that the xml processor expects an element locatedEntity inside the second device element. the earliest position at which it can be deduced that there will be no such element is the closing tag of said device element.

have a look at the schema document for namespace "urn:hl7-org:v3"; maybe location has been used erroneously instead of locatedEntity ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top