locked
Why does GetProperty<IContextManager>() return null? RRS feed

  • Question

  • Hello,

    I am connecting to a WCF service from a workflow using NetTcpContextBinding and SendActivity. When a WCF operation is called, then inside a WCF service I am trying to get hold of IContextManager using the following code:

    var cm = OperationContext.Current.Channel.GetProperty<System.ServiceModel.Channels.IContextManager>();

    However it is always null. Isn't context-aware binding supposed to give an access to a context information? And if not, how can I retrieve an IDictionary<string,string> context collection on a server side?
    Vagif Abilov
    Sunday, June 21, 2009 4:28 PM

Answers

  • Well, I think I've found the reason (and solution). Instead of trying to obtain IContextManager on the server I can simply check for IncomingMessageProperties. They will include among other properties a property with a key ContextMessageProperty where I can find my context.
    Vagif Abilov
    • Marked as answer by Marco Zhou Wednesday, June 24, 2009 6:26 AM
    Monday, June 22, 2009 11:58 AM

All replies

  • Why do you care on the service side?

    The context manager allows the client to be able to store the context so it can recreate a proxy with the required context to talk to the service
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Twitter: richardblewett
    Monday, June 22, 2009 8:59 AM
  • I care on the service side, because I want to make a call from the service via ReceiveActivity back to the original workflow instance. So it is essentially duplex communication, and to context data is a missing bit in the puzze. Consider the following scenario:

    1. Workflow instance starts. The workflow consists of Send and Receive activities to communication with WCF components.
    2. Send activity calls a WCF service, let's say it's a method RequestQuote.
    3. WCF service receives a qoute request and spawns a new thread that will send a reply.
    4. When the quote is prepared, WCF service creates a WCF channel that calls a method ReplyQuote. It communicates with a component that is wrpapped into a WF ReceiveActivity.

    Now if I explicitly pass a context as part of RequestQuote and set it prior calling ReplyQuote using channel.GetProperty<IContextManager>, everything works fine. But then my contract contains communication details. I'd rather customize communication channel to pass the context behind the scenes. And having Context property on both Send and Receive activities looks promising for my goal. It's just that I can't get hold of it in step (3) unless I pass it as a method parameter. It feels so little missing.
    Vagif Abilov
    Monday, June 22, 2009 9:12 AM
  • Well, I think I've found the reason (and solution). Instead of trying to obtain IContextManager on the server I can simply check for IncomingMessageProperties. They will include among other properties a property with a key ContextMessageProperty where I can find my context.
    Vagif Abilov
    • Marked as answer by Marco Zhou Wednesday, June 24, 2009 6:26 AM
    Monday, June 22, 2009 11:58 AM