I am currently writing a WCF duplex service using NetTcpBinding, and I came across an architecture question that I think I know the answer to, but hope I'm wrong.
Our service has stateful status, and we chose NetTcpBinding with PerSession InstanceContextMode . For various reasons, this is what we need. I am trying to break our extended interface (where large blocks of operations will not apply to many clients) into several smaller interfaces with operations logically grouped. Although this is simple enough to implement a single service that implements all contracts, Iโm not sure that it is possible to have several service contracts sharing one channel (or, moreover, my requirement, one session), and I would definitely be able to do this to make this work.
I could, of course, include everything in one contract and throw a FaultException when an incorrect operation is performed, but I really would like to break them down and not even add an endpoint for inapplicable contracts. Is what I'm looking for maybe?
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 to be able to establish one session from the client to the service, but use both IServiceA and IServiceB .
source share