views:

861

answers:

9

I have an internal enterprise app that currently consumes 10 different web services. They're consumed via old style "Web References" instead of using WCF.

The problem I'm having is trying to work with the other teams in the company who are authoring the services I'm consuming. I found I needed to capture the exact SOAP messages that I'm sending and receiving. I did this by creating a new attribute that extends SoapExtensionAttribute. I then just add that attribute to the service method in the generated Reference.cs file. This works, but is painful for two reasons. First, it's a generated file so anything I do in there can be overwritten. Second, I have to remember to remove the attribute before checking in the file.

Is There a better way to capture the exact SOAP messages that I am sending and receiving?

Thanks!

A: 

You can do this by creating a SoapExtention. Check this article.

Jordi
A: 

I used the following code is an example of how I captured SOAP requests in a application written a while back.

<System.Diagnostics.Conditional("DEBUG")> _
    Private Sub CheckHTTPRequest(ByVal functionName As String)
        Dim e As New UTF8Encoding()

        Dim bytes As Long = Me.Context.Request.InputStream.Length
        Dim stream(bytes) As Byte
        Me.Context.Request.InputStream.Seek(0, IO.SeekOrigin.Begin)
        Me.Context.Request.InputStream.Read(stream, 0, CInt(bytes))

        Dim thishttpRequest As String = e.GetString(stream)

        My.Computer.FileSystem.WriteAllText("D:\SoapRequests\" & functionName & ".xml", thishttpRequest, False)

    End Sub

Setting the conditional attribute like I did makes the compiler ignore the method call for all build types other than debug.

Sorry for the VB, it is forced upon me.

NotMyself
A: 

@Jordi - thanks, but like I said, I'm already doing that. It works great, but isn't ideal.

Rob
+2  A: 

Is this a webapp?

Place your SoapExtension code in a HTTPModule, and inject the SOAP envelope into the HTTPOutput stream.

That way, when in debug mode, I picture something like a collapsible div on the top of the page that lists all SOAP communication for that page.

FlySwat
A: 

@NotMyself - I'm not seeing where I would put the call to this method. I also see a reference to HttpContext in there. I'm making the web request call, not receiving one. Or, to put it another way, I'm the one consuming someone else's web service. I was asked for the exact SOAP I was sending them and for the SOAP that was returned to me from their service.

Rob
Ahh Sorry Rob, I jumped to the conclusion that you were working on the WebService side.
NotMyself
+2  A: 

I have a HTTPModule already built that does this, I'll strip out my company specific information and post the goodies later today.

Also, check out SoapUI, its a handy tool.

FlySwat
A: 

@Jonathan Holland - can't wait to see it. I'm having trouble imagining how this works since I'm the one making the request rather than having a request come in that I can inspect. Maybe my understanding of HttpModules is what is lacking!

Thanks again

Rob
A: 

@Jonathan Holland - I'd still be interested to see what you have if you get some extra time

Rob
+2  A: 

This seems to be a common question, as I just asked it and was told to look here.

You don't have to edit the generated Reference.cs. You can reference the extension in your application's app.config.

David Chappelle
Now that is awesome news. Thanks!
Rob