C# Getting XML SOAP response from autogenerated Re

2019-06-24 05:55发布

问题:

In visual studio 2008 using .net 3.5 i have consumed a WSDL which has automatically generated a Reference.cs. This was done by right clicking on References in my project and selecting "Add Web Reference"

Using this i can post to the web service and get valid responses through my ref and out objects. postValues() is a void method.

webService.postValues(ref value1, ref value2, out value3);

Using WireShark i can see the the request and full soap response on my network.

What im trying to figure out is how can i capture this raw SOAP response in my code. I would like to capture this for logging purposes and would rather not individually serialize each of the ref objects.

I cant see anyway to do this without modifying the automatically generated Reference.cs which id rather not do. Any help would be appreciated.

Edit: There doesnt seem to be a way to do this that i can see. Can anyone else confirm or deny this?

EDIT. Ill bump this just one more time to see if anyone knows.

回答1:

You have following options:

  1. Enable tracing for your web service in config, and dump all information into file. If you are using WCF instead of legacy web services, see this question on how to enable tracing for WCF.
  2. Implement your own SoapExtension and plug into message processing pipeline to intercept and dump incoming/outgoing soap messages. I think example in linked artice contain TraceExtension, which does exactly that.
  3. Modify generated Reference.cs and dump passed objects, as you specified.