title: Capturing data from a .Net web-service that fails with an HTTP 500 error code
body: <p>I have a .net web-service hosted in IIS 6.0 that periodically fails with an http 500 because a client connects to it with data that does not match the wsdl.</p>
  
  <p>Things like having an element specified in a method as being of type int and the inbound xml element contains a decimal number.</p>
  
  <p>WSDL element definition:</p>
  
  <pre><code>&lt;s:element minOccurs="1" 
      maxOccurs="1" 
      form="unqualified" name="ItemCount" type="s:int" &gt;  
  </code></pre>
  
  <p>provided element:</p>
  
  <pre><code>&lt;ItemCount&gt;1.0&lt;/ItemCount&gt;
  </code></pre>
  
  <p>This leaves a 500 error in the iis logs but no information of the soap fault returned or the input data that caused the error.</p>
  
  <p>Currently I have diagnosed several problems with data provided by capturing everything using wireshark but I'd like to know of other options that a perhaps less intrusive.</p>
  
  <p>Is there any way of capturing the data being sent that is causing the 500 errors (hopefully ONLY capturing the data when the 500 occurs)? Possibly by:</p>
  
  <ul>
  <li>Configuring IIS</li>
  <li>Configuring the web-service</li>
  <li>Changing the code of the web-service</li>
  </ul>
  
  <p><strong>EDIT</strong> after testing answer provided by tbreffni</p>
  
  <p>The answer that best fitted what I was after tbreffni's - there were several other good responses but the answer allows capture of the payload causing deserialization errors without running something like fiddler or wireshark.</p>
  
  <p>Info on actually getting a SOAP extension to run is a little light so I've included below the steps I found necessary:</p>
  
  <ul>
  <li>Build the SOAP extension as a .dll as per the <a href="http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapextension.aspx" rel="nofollow noreferrer">MSDN</a> article    </li>
  <li>Add the .dll to the bin directory for the service to trace</li>
  <li><p>In the web.config of the service to trace add the following to the webServices section, replacing the SOAPTraceExtension.TraceExtension and SOAPTraceExtension to match your extension.</p>
  
  <p>&lt;webServices&gt;<br>
  &nbsp;&nbsp;&lt;soapExtensionTypes&gt;<br>
  &nbsp;&nbsp;&nbsp;&nbsp;&lt;add type="SOAPTraceExtension.TraceExtension, SOAPTraceExtension" priority="1" group="0"/&gt;<br>
  &nbsp;&nbsp;&lt;/soapExtensionTypes&gt;<br>
  &lt;/webServices&gt;   </p></li>
  </ul>