Adding standard custom message headers for all service contracts

Topics: General Discussion Forum, July and December Releases Forum, Service Factory Modeling Edition Forum
Apr 3, 2008 at 5:59 PM
Hi,

Is there a way to always add standard message headers that are used for all service contracts and methods.

In our case, we need to send few fixed by client session parameters in message headers for all service method calls.

I am wondering if there is a way to specity this once and we will call service methods without much knowledge of this additional step.

Apr 3, 2008 at 7:09 PM
If that's a standard inyour org/team then I would suggest updating the text template files that generate Message Contracts (look in ServiceContractDsl project inside \Template\WCF or ASMX and add the header attribute/s in the MessageContract.tt file. You can find further samples on how to update tt files in the Extensibility Hands-on lab in this home page.
Apr 3, 2008 at 7:40 PM
Thank you charlyfriend!

We are mainly concerned from client calls: Setting up these properties on each operation service method call from client.

Is there anything at client-side like: Some standard context available in ServiceModel at client-side, that will save us from setting these headers per call.

Currently we create OperationContext and add headers in Proxy class. Can we create single OperationContext object and use it in all Proxy methods?

I am not sure if OperationContext created this way should not be shared across multiple methods. Technically I am able to share OperationContext this way but I am looking for some guidance on this.


Apr 3, 2008 at 8:16 PM
I am posting following details as FYI:
--------------------------------------------------------

Following link as all details I am looking for. It is what fits well for our need and I am impressed to see the flexibility in WCF

http://weblogs.asp.net/gsusx/archive/2006/08/10/Extending-WCF-clients.aspx

At high level we can add our own message inspector and add custom headers and watch all messages that go out.

Look for IClientMessageInspector interface - See above link for full details.

Apr 4, 2008 at 3:59 AM
RJ, using the message inspector strategy on the client side and intercepting with 'BeforeSendRequest' and adding ther headers there seems to be a good fit your your scenario.