This is a mirror of official site: http://jasper-net.blogspot.com/

Silverlight 4.0: Duplex Communication over Http using PollingDuplexHttpBinding

| Tuesday, June 28, 2011
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.dll

The 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.dll

Since 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 article

Step 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:


silverlight-duplex-service.png

Read more: net curry com
QR: ShowArticle.aspx?ID=726

Posted via email from Jasper-net

0 comments: