Compartir a través de


Building and Accessing Duplex Services

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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 referred to as a "server push") is useful when the server needs to notify the client of new information asynchronously, for example, to notify of the arrival of a new chat or e-mail message.

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. On the other hand, Silverlight 4 offers duplex services with models that are tied to either 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 from within an established session. The server will return a chunked HTTP response with as many messages as are currently pending, and then close the poll response. 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 the WS-Make Connection (WS-MC) Protocol uses polling to establish a back channel that enables server-initiated messages to be delivered to the client. This HTTP-based functionality is available in the system-provided PollingDuplexHttpBinding.

Cc645026.security(en-us,VS.95).gif Security Note:
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. In out-of-browser elevated applications, some of these requirements can be relaxed. For more information about sockets and how to configure your server for sockets access, see Working with Sockets.

WCF services enable duplex communication over TCP sockets with Silverlight clients through a NetTcpBinding with security turned off.

Cc645026.security(en-us,VS.95).gif Security Note:
Silverlight 4 does not support NetTcpBinding with security. Any information you send using this binding configuration is unencrypted and can be intercepted and modified by unauthorized third parties. Do not send sensitive information using this binding configuration.

Using the Add Service Reference tool to generate the client when the duplex service is configured with the NetTcpBinding results in the client being configured with a NetTcp binding.

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 about this protocol, see .NET Message Framing Protocol Specification.

Cc645026.security(en-us,VS.95).gif Security Note:
Running services that can be accessed by TCP sockets with Silverlight 4 clients may require configuration changes to your firewall.

In This Section

Reference

Send comments about this topic to Microsoft.

Copyright © 2010 by Microsoft Corporation. All rights reserved.