Wednesday, 15 July 2009

HttpWebRequest.DefaultMaximumErrorResponseLength

I usually use Google to hunt for solutions to my exceptions but this one proved to be a challenge with regards to the amount of digging that had to be done.

I encountered an issue with a .NET Client receiving a Soap Fault that was greater than 64K. This mean’t that a response stream greater than 64K got truncated and thus this exception.

[System.Xml.XmlException] = {System.Xml.XmlException: Unexpected end of file has occurred. The following elements are not closed: faultstring, soap:Fault, soap:Body, soap:Envelope. Line 2833, position 4.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextR...

Turns out you can set HttpWebRequest.DefaultMaximumErrorResponseLength=-1 for unlimited in code or the web.config / app.config

  

<system.net>
    <settings>
      <httpWebRequest maximumErrorResponseLength="-1"  />
    </settings>
  </system.net>



Lets hope with some indexing that this post serves you well!

No comments: