Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is exactly what duplex bindings were designed for. The two best choices you have are <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.nettcpbinding.aspx" rel="nofollow noreferrer">NetTcpBinding</a> or <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.pollingduplexhttpbinding(VS.95).aspx" rel="nofollow noreferrer">PollingDuplexBinding</a>.</p> <p>The former uses a TCP protocol which may not be suitable for your clients if they aren't on your network. However, it does allow two-way communication over a client-initiated socket. So the client doesn't need to be able to accept incoming connections. I recently used this on a project and it works very well. It's also very responsive. When client applications close, the session on the server immediately ends.</p> <p>The second option, PollingDuplexBinding is included in the Silverlight SDK. It uses a client-initiated "long" HTTP request. The request waits for messages that need to go out to the client and when they arrive, the client request returns. The client then initiates a new HTTP request back to the server. In other words, the client always has a pending HTTP request. This works well over firewalls and should be used when you're dealing with internet clients. However, I've found this to be not as responsive as NetTcpBinding. I may have been doing something wrong but it seemed like attempts to send callbacks to abandoned client sessions took a while to "time out".</p> <hr/> <p>Here's an example of the configuration file from my recent project that used NetTcpBinding for duplex communication. Note that other than some tweaks to service throttling I am pretty much using the defaults for this binding. But <a href="http://msdn.microsoft.com/en-us/library/ms731343.aspx" rel="nofollow noreferrer">there's all kinds of things</a> you can tweak such as receiveTimeout, inactivityTimeout, etc.</p> <pre><code>&lt;configuration&gt; &lt;system.serviceModel&gt; &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name=""&gt; &lt;serviceMetadata httpGetEnabled="true" /&gt; &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt; &lt;serviceThrottling maxConcurrentCalls="65535" maxConcurrentSessions="65535" maxConcurrentInstances="65535" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;bindings&gt; &lt;netTcpBinding&gt; &lt;binding maxConnections="65535"&gt; &lt;security mode="None" /&gt; &lt;/binding&gt; &lt;/netTcpBinding&gt; &lt;/bindings&gt; &lt;services&gt; &lt;service name="BroadcastService"&gt; &lt;endpoint address="" binding="netTcpBinding" contract="BroadcastService" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;/system.serviceModel&gt; &lt;/configuration&gt; </code></pre> <hr /> <pre><code>[ServiceContract( CallbackContract = typeof( IBroadcastCallback ) )] [ServiceBehavior( ConcurrencyMode = ConcurrencyMode.Multiple )] public class BroadcastService : IDisposable { [OperationContract(IsInitiating=true)] public long Subscribe( Guid clientID ) { // clients call this to initiate the session } [OperationContract(IsOneWay = true)] public void Publish( BroadcastMessage message ) { // client calls this to broadcast a message to // all other subscribed clients via callback } } [ServiceContract( Name = "BroadcastCallback" )] public interface IBroadcastCallback { [OperationContract( IsOneWay = true, AsyncPattern = true )] IAsyncResult BeginBroadcast(BroadcastMessage Message, AsyncCallback callback, object state); void EndBroadcast( IAsyncResult asyncResult ); } // interface </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload