Use multiple service contracts on a single channel or WCF session

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 .

+6
source share
1 answer

The default instance provider through the session channel will provide you with an instance to connect in your case. However, you can expand the instance provider to fetch an existing object from your own cache and return the same object.

As you copy the instances, you will use a special message header, etc. The appropriate channel / connection will be different for each proxy and also use different buffers / concurrency, but you can allow the service models to use the same instance, http://msdn.microsoft.com/en-us/magazine/cc163590 .aspx

+4
source

Source: https://habr.com/ru/post/899817/


All Articles