BizTalk Utilities CV ,   Jobs ,   Code library
 
Go to the front page to continue learning about XML or select below:

Contents

ReBlogger Contents

Previous posts in WSCF/WCF

 
 
Page 1577 of 21350

WCF: How to use Message Inspectors when using client callback on duplex channels.

Blogger : MSDN Blogs
All posts : All posts by MSDN Blogs
Category : WSCF/WCF
Blogged date : 2008 Dec 09

When using WCF you sometimes need to intercept message on your communication channel to do various stuff.

On the internet there are a lot of good examples on how to use Message inspectors.

http://weblogs.asp.net/paolopia/archive/2007/08/23/writing-a-wcf-message-inspector.aspx

http://msdn.microsoft.com/en-us/library/aa717047.aspx

Or just search for more examples: http://search.live.com/results.aspx?q=wcf+Message+inspector

 

Most of these examples do not describe what to do if your Message objects originates from the server to the client via callback. (Duplex channel)

If you attach an IEndpointBehavior implementation to the server and client, you have two places to attach inspectors.

For client the method below is called:

public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)

{

    // The add functions takes a IClientMessageInspector       

    clientRuntime.MessageInspectors.Add(this.inspector);

}

 

For servers the method below is called:

public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)

{

    // The add functions takes a IDispatchMessageInspector       

    endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this.inspector);

}

 

But when server calls the client through callback, it is now a client and the client turns into a server.

On the client side you would now need an IDispatchMessageInspector:

public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)

{

    // The add functions takes a IClientMessageInspector, which is used when client is client       

    clientRuntime.MessageInspectors.Add(this.inspector);

 

    // The add functions takes a IDispatchMessageInspector, which is used when the client is server       

    clientRuntime.CallbackDispatchRuntime.MessageInspectors.Add(this.inspector);

}

 

And the servers would need an IClientMessageInspector:

public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)

{

    // The add functions takes a IDispatchMessageInspector, which is used when the server is server       

    endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this.inspector);

 

    // The add functions takes a IClientMessageInspector, which is used when the server is client       

    endpointDispatcher.DispatchRuntime.CallbackClientRuntime.MessageInspectors.Add(this.inspector);

}


Read comments or post a reply to : WCF: How to use Message Inspectors when using client callback on duplex channels.
Page 1577 of 21350

Newest posts
 

    Email TopXML