Search code examples
c#wcfweb-servicessoap

View SOAP XML from WCF Creating Client


I have created a WCF Client with the SVCUTIL.exe following these instructions : http://msdn.microsoft.com/en-us/library/ms733133.aspx

It creates a app.config and a soapproxy.cs file to use.

I can not figure out any way of getting the raw XML for debugging purposes.

Google has lots of examples with adding a traceextension to the web.config file, however I do not have a web.config file... And the examples I found are for web.service not System.ServiceModel;

I need to access the XML soap calls so I can debug it?

UPDATE: I am trying to edit the config trace to view the SOAP XML.

I have added this to the app.config file

<configuration>
    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
                <listeners>
                    <add name="xml" />
                </listeners>
            </source>
            <source name="CardSpace">
                <listeners>
                    <add name="xml" />
                </listeners>
            </source>
            <source name="System.IO.Log">
                <listeners>
                    <add name="xml" />
                </listeners>
            </source>
            <source name="System.Runtime.Serialization">
                <listeners>
                    <add name="xml" />
                </listeners>
            </source>
            <source name="System.IdentityModel">
                <listeners>
                    <add name="xml" />
                </listeners>
            </source>
     </sources>

        <sharedListeners>
            <add name="xml"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="c:\log\Traces.svclog" />
       </sharedListeners>
    </system.diagnostics>
    </configuration>

However the trace log that comes up does not seem to include the raw XML


Solution

  • For quick debugging I use the WCF Test Client. Its quite simple and works with WCF and ASMX services. I also use it to consume services from third party applications written in Java (with wsdl definitions).

    Start -> Visual Studio 2010 Command Prompt -> wcftestclient.exe

    or

    Start -> Visual Studio 2008 Command Prompt -> wcftestclient.exe

    Information here: http://msdn.microsoft.com/en-us/library/bb552364.aspx

    This has the ability to view the XML/SOAP request and response.

    Also I use the XMLTraceListener. This generates the trace for me inside my application path and I am able to view the entire request/response body.

    Here is my web.Config section

    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel" switchValue="All">
                <listeners>
                    <add name="xmlTraceListener" />
                </listeners>
            </source>
            <source name="System.ServiceModel.MessageLogging" 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>