Duplex communication allows either the Windows Communication Foundation (WCF) service or the Silverlight version 4 client to initiate a message exchange, in contrast to the more commonly used request-reply pattern, where the Silverlight 4 client always initiates the message exchange. Duplex messaging (also known as "server push") is useful when the server needs to notify the client of new information asyncronously, the arrival of a new chat or email message for example.
WCF offers a way to model duplex services that abstracts away the specific duplex transport that is being used. You write your service once, and then change the transport depending on the requirements of your particular scenario. Silverlight 4 offers duplex services, on the other hand, with models that are tied either to an HTTP or a TCP-based duplex transport.
Duplex communication over HTTP: A Silverlight 4 client is not addressable over HTTP because the browser environment does not allow the creation of an HTTP listener. HTTP duplex communication with a Silverlight 4 client is achieved by having the client poll a destination server for messages within an established session. In addition to HTTP, two protocols are used by the Silverlight 4 polling duplex feature. The Net Duplex Protocol is implemented to establish the client session with a server and WS-Make Connection (WS-MC) uses polling to establish a back channel that enables server-initiated messages to be delivered to the client. This functionality is available in the system-provided PollingDuplexHttpBinding.
The polling duplex server listens on the standard HTTP port 80 so it is not typically blocked by firewalls.
Duplex communication over TCP: A sockets-networking API that works over the TCP protocol is also provided by Silverlight 4. This allows Silverlight 4 clients to open a bi-directional TCP connection to a server and implement duplex messaging over that connection. The Silverlight 4 sockets API is subjected to several security restrictions, specifically the need for the server to expose a policy file for both site-of-origin and cross-domain scenarios, and also for the restricted range of ports that can be used on the server. For more information on sockets and how to configure your server for sockets access, see Working with Sockets.
WCF allows duplex communication over TCP sockets via a customBinding. The binding should contain a tcpTransportBindingElement and either textMessageEncodingBindingElement or binaryMessageEncodingBindingElement. Both Silverlight 4 and WCF use the .Net Message Framing Protocol to negotiate the exchange of SOAP messages over a TCP connection. For additional information on this protocol, see NET Message Framing Protocol Specification.
Running services that can be accessed by TCP sockets in Silverlight 4 may require configuration changes to your firewall.
In This Section
Reference