Welcome to Windows Communication Foundation (WCF)
Top Tasks :

Adding Headers with MessageInspector

File Details
Downloads: 1879 File Size: 107kB
Posted By: Scott Mason Views: 4747
Date Added: Fri, Jun 23 2006
This sample implements the IClientMessageInspector and IDispatchMessageInspector interfaces to view the messages coming and going on both the client and server sides.  It implements the IEndpointBehavior to add these to the endpoint behaviors.
I manually add headers inside the clientMessageInspector.  On the server side I provide functions that will read the headers.  The headers I used for this example are the client side username and IP address.

Comments
 

Manish 3177 said:

Scott, the call frmServer.smi_OnAfterMessageReceived fails with an InvalidOperationException: "Cross-thread operation not valid: Control 'txtRequest' accessed from a thread other than the thread it was created on.". Here's a lazy man's workaround for this: void smi_OnAfterReceiveRequest(object source, MessageInspectorArgs args) { try { txtRequest.Text = args.RequestEnvelope; } catch (InvalidOperationException ex) { this.Invoke(new Server.ServerMessageInspector.MessageInspectorEventHandler(smi_OnAfterReceiveRequest), source, args); } } Likewise for frmServer.smi_OnBeforeRequestReceived.
Sun, Sep 10 2006 15:50
 

rajuChandra said:

That's the problem with the UI thread.do the following: 1. Add this in the class SynchronizationContext _uiSyncContext; 2.Then write the following two methods. public void Showdata(string t) { SendOrPostCallback callback = delegate(object state) { this.LoadData(state.ToString()); }; _uiSyncContext.Post(callback, t); } public void LoadData(string msg) { txtRequest.Text = msg; } 2. Add the following : void smi_OnAfterReceiveRequest(object source, MessageInspectorArgs args) { Showdata(args.RequestEnvelope.ToString()); } Cheers! rajuChandra
Thu, Aug 09 2007 1:47

Add Comment

Name (required)
Web Site (optional)
Comment (required)
Add

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us