<p>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.</p>

<p>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.</p>

<p><strong>Is There a better way to capture the exact SOAP messages that I am sending and receiving?</strong></p>

[{'answer_id': 54235, 'author': 'Jordi', 'author_id': 1893, 'author_profile': 'https://Stackoverflow.com/users/1893', 'pm_score': 1, 'selected': False, 'text': '<p>You can do this by creating a SoapExtention. Check <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconAlteringSOAPMessageUsingSOAPExtensions.asp" rel="nofollow noreferrer">this article</a>.</p>\n'}, {'answer_id': 54306, 'author': 'NotMyself', 'author_id': 303, 'author_profile': 'https://Stackoverflow.com/users/303', 'pm_score': 0, 'selected': False, 'text': '<p>I used the following code is an example of how I captured SOAP requests in a application written a while back.</p>\n\n<pre><code>&lt;System.Diagnostics.Conditional("DEBUG")&gt; _\n    Private Sub CheckHTTPRequest(ByVal functionName As String)\n        Dim e As New UTF8Encoding()\n\n        Dim bytes As Long = Me.Context.Request.InputStream.Length\n        Dim stream(bytes) As Byte\n        Me.Context.Request.InputStream.Seek(0, IO.SeekOrigin.Begin)\n        Me.Context.Request.InputStream.Read(stream, 0, CInt(bytes))\n\n        Dim thishttpRequest As String = e.GetString(stream)\n\n        My.Computer.FileSystem.WriteAllText("D:\\SoapRequests\\" &amp; functionName &amp; ".xml", thishttpRequest, False)\n\n    End Sub\n</code></pre>\n\n<p>Setting the conditional attribute like I did makes the compiler ignore the method call for all build types other than debug.</p>\n\n<p>Sorry for the VB, it is forced upon me.</p>\n'}, {'answer_id': 54327, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 2, 'selected': False, 'text': '<p>Is this a webapp?</p>\n\n<p>Place your SoapExtension code in a HTTPModule, and inject the SOAP envelope into the HTTPOutput stream.</p>\n\n<p>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.</p>\n'}, {'answer_id': 54368, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 2, 'selected': False, 'text': "<p>I have a HTTPModule already built that does this, I'll strip out my company specific information and post the goodies later today.</p>\n\n<p>Also, check out SoapUI, its a handy tool.</p>\n"}, {'answer_id': 307039, 'author': 'David Chappelle', 'author_id': 7475, 'author_profile': 'https://Stackoverflow.com/users/7475', 'pm_score': 3, 'selected': True, 'text': '<p>This seems to be a common question, as I just asked it and was told to look <a href="https://stackoverflow.com/questions/300674/getting-raw-soap-data-from-a-web-reference-client-running-in-aspnet">here</a>.</p>\n\n<p>You don\'t have to edit the generated <code>Reference.cs</code>.  You can reference the extension in your application\'s <code>app.config</code>.</p>\n'}]
['https://Stackoverflow.com/questions/54207', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2595/']