WCF Duplex Contract

Say I have a WCF maintenance contract like this

[ServiceContract(CallbackContract = typeof(ICallback1), SessionMode = SessionMode.Required)] public interface IService1 { // some methods } 

The service implementation has InstanceContextMode.Single for InstanceContextMode and ICallback1 - it's something like

 public interface ICallback1 { [OperationContract] void Report(int someValue); } 

Now on the client side, I can have a class that implements ICallback1, for example

 class Callback1 : ICallback1 { public void Report(int someValue) { // alert client } } 

and I create a customer service link like this

 Service1Client serviceClient = new Service1Client(new InstanceContext(new CallBack1())); 

which works great. Now the problem is that I have some clients that are not interested in a callback, so I decided that I did not need to implement a callback interface for such clients, so I tried this

  Service1Client serviceClient = new Service1Client(null); 

and

  Service1Client serviceClient = new Service1Client(new InstanceContext(null)); 

both reported that parameter cannot be null . My question is how can I create a link to a service without passing a callback object if the client is not interested in the callback. The only requirement is that all clients must talk to the same service, but otherwise I can restructure the service. Any thoughts?

EDIT:

I also tried SessionMode = SessionMode.Allowed for ServiceContract instead of SessionMode.Required , but that didn't help either.

+6
c # wcf duplex
source share
1 answer

Workaround: Remove CallbackContract from IService1. Create an IDuplexService1 that inherits from IService1 and contains a CallbackContract. Ask Service1Client to implement IDuplexService1. When creating the host instance, call ServiceHost.AddServiceEndpoint for IService1 and IDuplexService1.

+2
source share

All Articles