Many a times, the requirement demands that the WCF Service pushes data to the application that is consuming it, over the session established between client application and the WCF service. This mechanism can be termed as Callback. WCF actively supports callback to its client, over the instance context established. To understand this scenario, think of it like the WCF service becomes the client and the client becomes the service.
BasicHttpBinding and WSHttpBinding do not support callback. To support callback over HTTP transport, WCF provides WSDualHttpBinding. The WSDualHttpBinding sets up two channel - one for calls from client to service and other from service to client. Whenever you create a Service, it can have only one callback contract. When a proxy is created for the Service with CallBack, the base class of the proxy is the DuplexClientBase<T>. This is used to create channels for the duplex service and this channel is the associated with the callback object.
Enough of theory, let’s create a WCF service, Host and Client callback.
Step 1: Open VS2010 and create a Blank solution, name it as ‘WCF_Callback_Contract’. In this solution, add a new WCF Service application and name it as ‘WCF_CallBack_Service’. Rename IService1.cs to Iservice.cs and Service1.svc to Service.svc.
Step 2: Open IService.cs and add the following ServiceContract, Callback contract interface and a DataContract, as shown below:
Read more: dot Net Curry
0 comments:
Post a Comment