In a real world application, many-a-times it is required that the application performs a two-way communication i.e. the client application sends request to the service and then service should have capability to initiate action itself and send the data back to the client. In Silverlight, we can perform this kind of operation using Socket programming as well as using Duplex bindings. In Silverlight 4.0, we can do this using net.tcp binding. In this small article, I have used Polling Duplex communication. In WCF service, duplex communication is implemented using PollingDuplexBinding. When you install Silverlight, you get the following path where the polling duplex assembly is stored: C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Server\System.ServiceModel.PollingDuplex.dllThe above assembly reference is used by the WCF Service for the Duplex communication mechanism and the assembly used by the Silverlight client application is available at: C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\System.ServiceModel.PollingDuplex.dllSince the communication between Silverlight 4 and WCF is performed using Http, the Silverlight client has to send the request to the service to initiate the communication. Once this connection is established, the PollingDuplexBinding allows the established channel to keep alive, until the timeout occurs. Let’s see a practical implementation in this articleStep 1: Open VS2010 and create a new Silverlight application, name it as ‘SL4_Duplex_Service’. You will now see the ‘SL4_Duplex_Service.Web’ host project. Step 2: In the Web host project, add a reference to the ‘System.ServiceModel.PollingDuplex.dll’ from the following path:C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Server\System.ServiceModel.PollingDuplex.dll Step 3: In the Web host project, add a new Silverlight enabled WCF service and call it ‘MyService.svc’. Also in the project, add a new Interface file and name it as ‘IService.cs’, the same file will define the ServiceContract and OperationContract as shown below:
Read more: net curry com
QR:
QR:
0 comments:
Post a Comment