Tuesday, 4 November 2014

Fiddler came to my help!

Background was that I needed to capture the soap request we sent to a particular web service to trace why it casted a SoapException for certain types of data that we needed to send. The web client was created in c# Studio Express 2010 a while ago.

The first approach was to try to turn on the excellent System.Diagnostics that I used before. To recap:

1. Open up the app.config and add the following block within the system.serviceModel tag:

<diagnostics>
<messageLogging logEntireMessage="true"
                maxMessagesToLog="300"
                logMessagesAtServiceLevel="true"
                logMalformedMessages="true"
                logMessagesAtTransportLevel="true" />
</diagnostics>


2. Turn on the diagnostics for all the listeners, add outside the system.serviceModel tag:
<system.diagnostics>
  <sources>
    <source name="System.ServiceModel"
            switchValue="All" propagateActivity="true">
      <listeners>
        <add name="xmlTraceListener" />
      </listeners>
    </source>
    <source name="System.ServiceModel.MessageLogging"
            switchValue="All" >
      <listeners>
        <add name="xmlTraceListener" />
      </listeners>
    </source>
    <source name="System.IdentityModel" switchValue="All" >
      <listeners>
        <add name="xmlTraceListener" />
      </listeners>
    </source>
    <source name="System.Runtime.Serialization" switchValue="All" >
      <listeners>
        <add name="xmlTraceListener" />
      </listeners>
    </source>
  </sources>
  <sharedListeners>
    <add name="xmlTraceListener"
         type="System.Diagnostics.XmlWriterTraceListener"
         initializeData="ApplicationTrace.svclog" />
  </sharedListeners>
  <trace autoflush="true" />
</system.diagnostics>


3. Do a call and look in the svclog for the messages.

No, that did not work at all!
After closer examination I realized all the references were added as Web References by some reason so the configuration was not done through the app.config at all.

Ok, lets do new Service References!

But no, that was not possible as I am not a user on the customer's domain and therefore cannot do the service discovery the normal way through the add Service Reference box as the services requires authentication.

Ok, try to add authentication to the url on the form http://username:password@xxx.yyy.com. No that is now disabled in newer Internet Explorers. There was a regedit hack to enable it but it didn't work anyway as I cannot add the username in the form: domain\username as I am not on the same domain!

So finally I gave up trying to add the service reference. This might be tricky once they decide to update the wsdl so I might need to remember that when that day comes...

But instead I installed Fiddler and it was able to see the packages at once just in the form I needed and I could solve the issue!

The issue was an error in the customer's wsdl that didn't specify any default values for strings, but had default values for all int and decimals. As I then tried to send the xml with all fields omitted, threw a Soap exception as the strings were assigned as mandatory in the wsdl.

I immediately identified the missing fields in the soap message with the help of Fiddler and could adjust the code to fill the fields with blanks to make the SoapException go away.

No comments:

Post a Comment