Question

Hi I need to create wcf service with call back. Because the service need to update the windows UI for long operation. Can you help me with the suitable configuration for wcf service and client?

Was it helpful?

Solution

Configure in web.xml as wsdualhttpbinding. because while using call back methods http is a stateless protocol so you need to use wsdualhttpbinding inturn to call a method implemented on the client side.

Define interface with callback method and implement that method in client side.

Defining and configuring a callback contract:

public interface IMyContractCallback
{
    [OperationContract]
    void OnCallback();
}
[ServiceContract(CallbackContract = typeof(IMyContractCallback))]
public interface IMyContract
{
    [OperationContract()]
    void MyMethod();
}

Client callback setup:

class MyServiceClient:DuplexClientBase,IMyContract
{
    public MyServiceClient(InstanceContext callbackCntx)
        : base(callbackCntx)
    {            
    }
    public void MyMethod()
    {
         base.Channel.MyMethod();
    }
}

Service-Side Callback Invocation:

IMyContractCallback
callbackInstance=OperationContext.Current.GetCallbackChannel();
        callbackInstance.OnCallback();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top