DotNetDave

Hi,

I am got the following situation and would love to hear peoples feedback on whether i am doing this in the correct way for WCF.

Currently our application has its own context class similar to HttpContext and is accessed using the Current property. This class contains a number of properties such as ClientName, ApplicationName, Status etc etc. We would like to be able to pass this information over the wire to our remote services hosted in WCF, but we dont want to have to explicitly the information on every method call.

My current thinking to have a class that implements the IClientMessageInspector and IDispatchMessageInspector interfaces. In the IClientMessageInspector.BeforeSendRequest i take the current context and then create a new message header for it, this is then added to the request headers collection.

On the service side the IDispatchMessageInspector.AfterReceiveRequest looks for the header and moves it into the understood headers collection. The context object then has a method in it to look through the current OperationContext's understood headers and the deserializes the appropriate header.

Can anyone comment on this approach, the pros and cons of it or whether is a better way of achieveing the same things

Thanks

Dave



Re: Windows Communication Foundation (Indigo) Passing application context information to servies

David Wortendyke - MSFT

Hi Dave,

Using message inspectors like you describe is the recommended pattern for augmenting a message like this without modifying each call-site. There are two other alternatives that can sometimes be considered. One is to use the OperationContextScope to manually put things in the headers and extract them on the other side, but of course this requires that you change each call-site which you want to avoid. The other is to write a custom channel layer, but this is a lot of work and is probably overkill if you just want to use message headers to pass some additional context.

So you've picked the right approach. :)

Regards,
David






Re: Windows Communication Foundation (Indigo) Passing application context information to servies

DotNetDave

Hi David,

I havent seen the OperationContextScope before when you mentioned i would have to do this at each call site, what do you actually mean. Could i not just create some behavior on the service and client like i already have to change the OperationContextScope with my own stuff to be passed across.

Is passing this information using headers the correct way to do this

Thanks

Dave