Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you meant that you want to see the XML at the client, not trace it at the server. In that case, your answer is in the question I linked above, and also at <a href="http://msdn.microsoft.com/en-us/library/ms733786.aspx" rel="noreferrer">How to Inspect or Modify Messages on the Client</a>. But, since the .NET 4 version of that article is missing its C#, and the .NET 3.5 example has some confusion (if not a bug) in it, here it is expanded for your purpose.</p> <p>You can intercept the message before it goes out using an <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iclientmessageinspector.aspx" rel="noreferrer">IClientMessageInspector</a>:</p> <pre><code>using System.ServiceModel.Dispatcher; public class MyMessageInspector : IClientMessageInspector { } </code></pre> <p>The methods in that interface, <code>BeforeSendRequest</code> and <code>AfterReceiveReply</code>, give you access to the request and reply. To use the inspector, you need to add it to an <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.aspx" rel="noreferrer">IEndpointBehavior</a>:</p> <pre><code>using System.ServiceModel.Description; public class InspectorBehavior : IEndpointBehavior { public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { clientRuntime.MessageInspectors.Add(new MyMessageInspector()); } } </code></pre> <p>You can leave the other methods of that interface as empty implementations, unless you want to use their functionality, too. Read the how-to for more details.</p> <p>After you instantiate the client, add the behavior to the endpoint. Using default names from the sample WCF project:</p> <pre><code>ServiceReference1.Service1Client client = new ServiceReference1.Service1Client(); client.Endpoint.Behaviors.Add(new InspectorBehavior()); client.GetData(123); </code></pre> <p>Set a breakpoint in <code>MyMessageInspector.BeforeSendRequest()</code>; <code>request.ToString()</code> is overloaded to show the XML.</p> <p>If you are going to manipulate the messages at all, you have to work on a copy of the message. See <a href="http://msdn.microsoft.com/en-us/library/ms734675.aspx" rel="noreferrer">Using the Message Class</a> for details.</p> <p>Thanks to <a href="https://stackoverflow.com/questions/1217374/intercept-messages-in-a-wcf-client/1218139#1218139">Zach Bonham's answer</a> at another question for finding these links. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload