views:

748

answers:

4

What is the best way to inspect the calls & responses from a web service in .NET?
I'm interacting with a Web Service written in Perl and running into issues.
How can I capture the text of the call and response?

UPDATE:
Based on comment to clarify: I'd like to do it via .NET so I can log it or email it when an issue arises.

+3  A: 

Fiddler is your best friend in the wonky world of web services.


No, it doesn't do anything inside the code as pointed out. Nor do you want it to--debugging should NOT change semantics of the process, or you are debugging your debugging code.

Also, I hearts me some wireshark, but fiddler is a bit better for HTTP stuff as it is designed to focus on HTTP. If I'm grabbing bytes off the wire, it is wireshark all the way.

Wyatt Barnett
Anything to do it inside the code?
tyndall
Fiddler acts as a proxy between any process on your local computer and the server you're talking to (showing all the traffic in between)
Jason Watts
What's the use case of having the traffic within your code? Are you building a WPF version of fiddler?
Jason Watts
Fiddler is a cool tool though +1
tyndall
I know how Fiddler works. Just I'm looking for something that I can instrument into the actual code. Notify me of odd results...and maybe alert me. Wouldn't know how to make Fiddler do that.
tyndall
Gotcha. That wasn't clear at all from the question, perhaps you might wish to edit it.
Wyatt Barnett
I will make the edit/update
tyndall
A: 

Personally, I like to use a packet sniffer, like Wireshark. It's a great tool for inspecting any sort of network traffic.

Jacob
+4  A: 

You can do this by creating a SoapExtension and enabling it in your web service client:

System.Web.Services.Protocols.SoapExtension Class (MSDN)

The link above provides a skeleton of sample code that logs requests/responses to a file.

To enable in your application add the following to your web.config or app.config:

<webServices>
    <soapExtensionTypes>
        <add type="YourNamespace.TraceExtension, AssemblyName" 
             priority="0" group="High"/>
    </soapExtensionTypes>
</webServices>

My own SOAP tracing extension is implemented in its own project/assembly. Whenever I need to debug the request/response I just drop the DLL in the application folder (/bin for ASP.NET) and add the reference to the config file as above.

For example:

<webServices>
   <soapExtensionTypes>
      <add 
         type="DebugTools.SOAP.SOAPTrace.SoapTraceExtension, DebugTools.SOAP" 
         priority="0" group="High"/>
   </soapExtensionTypes>
</webServices>

DebugTools.SOAP.SOAPTrace is the namespace of the SoapTraceExtension
DebugTools.SOAP is the name of the assembly containing the soap trace code.

Kev
Pretty neat, never seen that one. Definitely handy in environments where you can't install tools.
Wyatt Barnett
Yep...it's nice that you can drop in the logging without having to modify your application code.
Kev
Sweet! Going to try this out. Thanks. +1. Will bring back feedback.
tyndall
Thanks... this was the resolution to a rather lengthy search.
Kyle B.
A: 

In a WCF web service or client, you can simply configure tracing and/or message logging. This can be done at runtime, with no code changes.

John Saunders
I'm consuming web service written in Perl (Not by choice). Client is written in .NET 3.5. Can I still take advantage of the tracing / logging on the client?
tyndall
No, you can't. Please edit your answer to say that your client is PERL. The fact you said you'd like to do it in .NET made me think the client was .NET.
John Saunders