Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Log or View Call / Response of a SOAP WebService

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.

like image 785
BuddyJoe Avatar asked Dec 09 '22 20:12

BuddyJoe


2 Answers

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.

like image 190
Kev Avatar answered Dec 12 '22 09:12

Kev


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.

like image 31
Wyatt Barnett Avatar answered Dec 12 '22 10:12

Wyatt Barnett