views:

306

answers:

5

I am very new to WCF and SOAP messaging but I have managed to put together a reasonably good client which I am using to download news stories from a media organisation. I have generated proxy classes which obviously abstract a lot away and mean that I am basically just creating objects, calling methods and iterating through results.

My issue is that I have raw XML examples of what the calls to the web service should look like and I want to be able to "compare" these to the calls that I am making. Basically I need to ensure that the calls that I am making are the same as the example XML files for testing purposes.

Does what I am asking make sense or am I going about this the wrong way? Please let me know if there is any necessary information that I have left out, I could bang on for paragraphs but am not sure what information is relevant. Thanks in advance.

+1  A: 

Have you used the Service Trace Viewer tool from Microsoft? This MSDN page will give you the details on how to use it.

slugster
Thanks for the response, slugster. I am going to take a look at this and will post back how I go.
dave
A: 

The stock answer for this is to use fiddler as a proxy - this will allow you to view the outgoing and incoming messages between your client and the service.

Can't yet speak from personal experience, however team members developing for me (in a former life) have - quite rightly - coded up our service wrappers with built in support for use of a proxy explicitly to simplify use of fiddler.

Murph
Thanks for the response. The problem with using Fiddler is that it is a SSL secured web service so there are issues of the web service not liking Fiddler's certificate because of it being an unrecognised CA. I have tried overriding server certificate validation but there is something happening with the web service that it does not like that at all. The answer may be to just keep playing with this
dave
Have you tried Live HTTP headers, a plugin of Firefox? I am not sure if it supports CA, but worthwhile to give it a shot.
Jay Zeng
+2  A: 

You can use WCF tracing to log the raw XML messages. The following is .config enables WCF tracing with raw message logging:

<configuration>
  <system.serviceModel>
    <diagnostics>
      <messageLogging maxMessagesToLog="30000"
              logEntireMessage="true"
              logMessagesAtServiceLevel="true"
              logMalformedMessages="true"
              logMessagesAtTransportLevel="true">
      </messageLogging>
    </diagnostics>
  </system.serviceModel>
  <system.diagnostics>
    <sources>
      <source name="System.IdentityModel" switchValue="Verbose" logKnownPii="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- Log all messages in the 'Messages' tab of SvcTraceViewer. -->
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- ActivityTracing and propogateActivity are used to flesh out the 'Activities' tab in
           SvcTraceViewer to aid debugging. -->
      <source name="System.ServiceModel" switchValue="Error, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <!-- This records Microsoft.IdentityModel generated traces, including exceptions thrown
           from the framework. -->
      <source name="Microsoft.IdentityModel" switchValue="Warning">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="trace.e2e" />
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>
</configuration>

You can read more about WCF Tracing from MSDN: Configuring Tracing.

Microsoft provides a Service Trace Viewer Tool to read .svclog files.

Make sure the path defined in initializeData is writable by your service.

Daniel Vassallo
A: 

You can create your own message inspector using the IClientMessageInspector interface and get the raw messages for both the request and response.

Here's a good post on how to do it ==> http://www.keithelder.net/blog/archive/2008/01/15/How-to-Get-Around-WCFs-Lack-of-a-Preview-Web.aspx

WayneC
A: 

I don't know much about WCF, but you could redirect your connection to a different web server on your network that logged the body somewhere. This would allow you to see exactly what you are sending, but would require some infrastructure work. This could be a web server running on your development machine.

Aaron