Search code examples
c#wcfduplex

WCF - Can the callback interface specified as a generic one?


Consider that I am gonna create one generic interface for subscribing and unsubscribing to a duplex service, for ex:

[servicecontract(CallbackContract=typeof(ICallbackService))]
public interface IService
{
 [operationcontract]
 void sub();
 [operationcontract]
 void unsub();
}

public interface ICallbackService
{
[operationcontract(isoneway=true)]
void senddata(object data);
}

public interface IFirstService:IService{}
public interface ISecondService:IService{}

And on the client side while creating duplex channel instance, i have my callback instance as

class callbackclass:ICallbackService{
public void senddata(object d){}
}

and when using

DuplexChannelFactory<IFirstService> fact=new DuplexChannelFactory<IFirstService>(new instancecontext(new callbackclass()),new wsdualhttpbinding(),"address");
var chan=fact.CreateChannel();

I am facing a issue saying the contract IFirstService doesnt define any operations.Can any one help with this kind of scenario.


Solution

  • Unfortunately you can't. It's not possible to do that, as soap does not support this. Please read this article.