Question

I'm in the process of writing a duplex WCF service using NetTcpBinding, and I've run into an architecture question that I think I know the answer to, but hope that I'm wrong.

Our service is stateful, and we've selected NetTcpBinding with PerSession InstanceContextMode. For various reasons, this is something that we require. I'm trying to break up our larger interface (where large blocks of the operations would not apply to many clients) into multiple smaller interfaces with the operations logically grouped. While it's simple enough to have a single service implementation implement all of the contracts, I'm not sure if it's possible to have multiple service contracts share a single channel (or, more to my requirement, a single session), and I'd definitely need to be able to do that in order to make this work.

I could, of course, include everything on one contract and throw FaultExceptions when an invalid operation is performed, but I'd really like to be able to break these up and not even add an endpoint for inapplicable contracts. Is what I'm looking for possible?

TL;DR Version:

I need to be able to do this:

[ServiceContract]
public interface IServiceA
{
    [OperationContract]
    void Foo();
}

[ServiceContract]
public interface IServiceB
{
    [OperationContract]
    void Bar();
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class Service : IServiceA, IServiceB
{
    ...
}

And be able to establish one session from the client to the service but use both IServiceA and IServiceB.

Was it helpful?

Solution

The default instance provider over a sessionful channel will give you an instance per connection in your case. You can however extend the instance provider to pick up an existing object from your own cache and return the same object.

How you correlate instances will be upto you using some special message header etc. The underlying channel/Connection will be different for each proxy and also use differnt buffers / concurrency models but you can allow service model to use the same instance. http://msdn.microsoft.com/en-us/magazine/cc163590.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top