S h o r t S t o r i e s

// Tales from software development

Archive for November 2010

Web service method returns ‘There is an error in XML document’

leave a comment »

When a web service method returns data that doesn’t conform to the schema you’re likely to get a SOAPException with an error message such as:

There is an error in XML document (1, 4309)

The two numbers are the line and column numbers where the deserialization of the SOAP XML failed and will vary according to the response data that was being sent.

This problem showed up recently with a Windows service that I wrote to retrieve patient data from a clinical data store. The vendor of the clinical data store product was adamant that there was no fault with their product as it was successfully returning a response to the request for a specific patient.

It was clear to me that the response was not valid but, unfortunately, there doesn’t seem to be an easy way to get the SOAP response to examine it and determine what’s wrong with it. After a lot of digging around I found the following diagnostic settings that produce a trace file that includes the SOAP response:

            <source name="System.Net">
                    <add name="System.Net"/>
            <source name="System.Net.Sockets">
                    <add name="System.Net"/>
            <add name="System.Net" value="Verbose" />
            <add name="System.Net.Sockets" value="Verbose" />
            <add name="System.Net"
        <trace autoflush="true" />

These settings need to be added to your .NET application’s .config file.

I knew from the exception stack that the error occurred when a DateTime field was being deserialized. The schema defined the value as an xsd:date value and the XmlSerializationReader.ToDate() method was being called. This uses a format string containing date components only, i.e. no time components.

When I looked at the SOAP response in the trace file I could see that the value being passed in this field contained ‘2010-10-25T00:00:00’. The time component was not valid according to the schema and was causing XmlSerializationReader.ToDate() to fail.

Despite saying that there was no problem with their product, when I passed this information to the vendor of the clinical data store product they confirmed that there was a known issue that resulted in the response being sent without being validated against the schema.


Written by Sea Monkey

November 12, 2010 at 12:00 pm

Posted in Debugging

Tagged with