In C#, how would I capture the SOAP used in a web service call?

陌路散爱 提交于 2019-12-21 07:03:04

问题


I have a C# application that is a client to a web service. One of my requirements is to allow capturing the SOAP that I send, so that if there is a problem, I can either fix the bug, or demonstrate that the problem is in the service I am calling.

My WebReference proxy service class derives from System.Web.Services.Protocols.SoapHttpClientProtocol as usual. If I had a magic wand, I would make this base class implement an event OnPost that I could handle to write the SOAP into my logs and continue.

Short of running a packet sniffer like WireShark, is there an easy way to get this level of logging?


回答1:


I think what you are looking for is addressed in this question:

Getting RAW Soap Data from a Web Reference Client running in ASP.net

It looks like a lot of code though.




回答2:


If the application is running on your local box and the web service isn't doing anything funky, you can use Fiddler. Fire Up IE, run Fiddler, and you'll see your web service calls go through fiddler's proxy too.

I just used this this morning to do almost the same thing. I had to prove the data my web service was sending wasn't messed up.




回答3:


To see this traffic in fiddler use the following code:

mySoapHttpClientProtocol.Url = mySoapHttpClientProtocol.Url.Replace("localhost", "localhost.fiddler");

Otherwise, Visual Studio's built in web server will bypass all proxies.




回答4:


Take a look at SoapExtensions.

They are what you need.




回答5:


For some reason Fiddler was not showing my local service calls when using the ASP.NET Development Server that comes with Visual Studio. To get around this I changed the web service Url at runtime to be the Fiddler port, just to capture the SOAP message.

You can do this from the Immediate window, for example:

myservice.Url = "localhost:8888" (or whatever port you have Fiddler on)

I used the SoapUI client to test responses.




回答6:


Just "." add the address in your endpoint after "localhost". like this:

      <endpoint address="http://localhost.:8868/FEInvoice.asmx" binding="basicHttpBinding"
    bindingConfiguration="FEInvoice_Test" contract="EInvoiceIntegration.FEInvoiceSoap"
    name="FEInvoice_Test" />


来源:https://stackoverflow.com/questions/306852/in-c-how-would-i-capture-the-soap-used-in-a-web-service-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!