views:

638

answers:

3

I'm calling a third-party vendor's external SSL web service from a .NET 3.5 client (WinForm). The vendor has asked me to send them the Soap Header to verify why things aren't working.

I used WireShark to capture packets, but since the web service is SSL, the packets are encrypted.

Is there a few magic lines of code to add to my C# client to save or display the Soap Envelope either right before I call their web/method or right after?

+1  A: 

How exactly are you accessing the web service? Are you using WCF or another mechanism?

One way that should always work is to use Fiddler. It basically acts like a proxy, intercepting the calls between your client and the web service (or any HTTP call, really) and then providing you with the contents of the request and response.

From there, you can get the SOAP envelope and send it to the vendor.

If you are using WCF, you could use a custom endpoint behavior to inject a IClientMessageInspector implementation. This implementation would have access to the Message (which is the object representation of the SOAP envelope) instance both before the request is sent to the server (through the BeforeSendRequest method implementation) as well as after you receive the reply (through the AfterReceiveReply method implementation).

casperOne
Forgot about Fiddler (I had switched to WireShark because it captures local packets which I think Fiddler did not). My title, but not question stated it was asmx. I did an "Add Web Ref" and calling the .asmx's proxy. Can you actually add a service reference to an .asmx and use WCF - that sounds a little strange.
NealWalters
I'm looking at inspectors tab, then sub-tab of xml and it's blank. Would that mean no Soap Header? Actually they were asking for the entire SOAP message. I have my request in Fiddler, but still don't see it all.
NealWalters
I saw Fiddler Option "Decrypt Traffic" check-box on, then got this error: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
NealWalters
+1  A: 

In .NET 2.0 I used Web Service Extensions 3.0 and implemented a PolicyAssertion and a SoapFilter. The ProcessMessage function will give you complete access to save/modify the soap header and body.

gbogumil
Thanks. I have found good examples of the override method - but not sure what class to tie it to. Does it relate to some class in my existing proxy?
NealWalters
I used WSE3UTIL.exe to generate the service proxies for the services I consumed. I acutally put all that in a separate project and then referenced that project from the project which consumes them because it speeds comilation time.Tying them together is done in a policy config file. You need to create a policy in the config and specify a type which implements PolicyAssertion in it. Let me know if you can't find an example. Then the final piece of the puzzle is this; when you instantiate your service class you have to call SetPolicy and pass the name you defined in the policy config.
gbogumil
Hmmm... I'm not even using WSE3 right now, because so far no need. I was hoping to just add a few lines of code to my existing program, rather than change the whole plumbing. I'm still debating if it's worth the investment of time. Thanks.
NealWalters
http://www.codeproject.com/KB/webservices/Soap_Extension_Progress.aspx This seems to show the non-WSE way to do it. Except most of the examples I see are for the server, not for the client.
NealWalters
A: 

envelope.Save("c:\filename.xml");

joe