Today a web service call was failing in a way I'd never seen before:
System.Xml.XmlException: Unexpected end of file has occurred. The following elements are not closed: faultstring, soap:Fault, soap:Body, soap:Envelope. Line 905, position 45.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String arg)
at System.Xml.XmlTextReaderImpl.ThrowUnclosedElements()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.ReadString()
at System.Xml.XmlTextReader.ReadString()
at System.Xml.XmlReader.ReadElementString()
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadSoapException(XmlReader reader)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
System.InvalidOperationException: Response is not well-formed XML.
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at [...]
I fired up Fiddler2 to see what was going on.
This is a local web service, with a location set in the application's config file. I modified the configuration to include the fully-qualified domain name instead of using localhost.
<Customer.Properties.Settings>
<setting name="Customer_SomeService" serializeAs="String">
<value>http://fully-qualified-name.intranet.solien.com/Customer.Service/SomeService.asmx</value>
</setting>
</Customer.Properties.Settings>
I re-ran the unit test that called the failing web method with Fiddler2 attached, and here's what I saw:
Somehow the long message in the unhandled SqlException caused invalid XML to be returned, or caused the wrong content length to be returned.