WCF and Proxies - Binding and Reliability
(Page 5 of 6 )
In WCF, reliability is controlled and configured in the binding. A particular binding can support or not support reliable messaging, and if supported, it can be enabled or disabled. Which binding supports which reliability value is driven by the target scenario for that particular binding. Table 1-2 summarizes the relationship between binding, reliability, and ordered delivery and their respective default values.
Table 1-2. Reliability and binding
| Name | Supports reliability | Default reliability | Supports ordered | Default ordered |
|---|
| BasicHttpBinding | No | N/A | No | N/A |
| NetTcpBinding | Yes | Off | Yes | On |
| NetPeerTcpBinding | No | N/A | No | N/A |
| NetNamedPipeBinding | No | N/A (On) | Yes | N/A (On) |
| WSHttpBinding | Yes | Off | Yes | On |
| WSFederationHttpBinding | Yes | Off | Yes | On |
| WSDualHttpBinding | Yes | On | Yes | On |
Table 1-2. Reliability and binding (continued)Name | Supports reliability | Default reliability | Supports ordered | Default ordered |
NetMsmqBinding | No | N/A | No | N/A |
MsmqIntegrationBinding | No | N/A | No | N/A |
Reliability is not supported by theBasicHttpBinding,NetPeerTcpBinding, and the two MSMQ bindings,NetMsmqBindingandMsmqIntegrationBinding. The reason is that theBasicHttpBindingis oriented toward the legacy ASMX web services world, which does not have reliability.NetPeerTcpBindingis designed for broadcast scenarios. The MSMQ bindings are for disconnected calls, where no transport session is possible anyway.
Reliability is always enabled onWSDualHttpBindingto keep the callback channel to the client alive even over HTTP.
Reliability is disabled by default but can be enabled on theNetTcpBindingand the various WS bindings. Finally, theNetNamedPipeBindingis considered inherently reliable because it always has exactly one hop from the client to the service.
Ordered Messages
Message reliability also provides ordered delivery assurance, allowing messages to be executed in the order they were sent, not in the order in which they were delivered. In addition, it guarantees that messages are delivered exactly once.
WCF lets you enable reliability but not ordered delivery, in which case messages are delivered in the order in which they were received. The default for all bindings that support reliability is that when reliability is enabled, ordered delivery is enabled as well.
Configuring Reliability
You can configure reliability (and ordered delivery) both programmatically and administratively. When you enable reliability, you must do so on both the client and the service host sides, otherwise the client will not be able communicate with the service. You can only configure reliability for the bindings that support it. Example 1-23 shows the service-side config file that uses a binding configuration section to enable reliability when using the TCP binding.
Example 1-23. Enabling reliability with the TCP binding
<system.serviceModel>
<services>
<service name = "MyService">
<endpoint
address = "net.tcp://localhost:8000/MyService"
binding = "netTcpBinding"
bindingConfiguration = "ReliableTCP"
contract = "IMyContract"
/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name = "ReliableTCP">
<reliableSession enabled = "true"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
When it comes to programmatic configuration, the TCP and the WS bindings offer slightly different properties for configuring reliability. For example, theNetTcpBindingbinding accepts a Boolean construction parameter for enabling reliability:
public class NetTcpBinding : Binding,...
{
public NetTcpBinding(...,bool reliableSessionEnabled);
//More members
}
You can only enable reliability at construction time, so when you set reliability programmatically, you need to construct the binding as reliable:
Binding reliableTcpBinding = new NetTcpBinding(...,true);
NetTcpBindingalso offers the read-onlyReliableSessionclass, letting you retrieve the reliability status:
public class ReliableSession
{
public TimeSpan InactivityTimeout
{get;set;}
public bool Ordered
{get;set;}
//More members
}
public class OptionalReliableSession : ReliableSession
{
public bool Enabled
{get;set;}
//More members
}
public class NetTcpBinding : Binding,...
{
public OptionalReliableSession ReliableSession
{get;}
//More members
}
Next: Requiring Ordered Delivery >>
More Windows Scripting Articles
More By O'Reilly Media
|
This article is excerpted from chapter one of Programming WCF Services, written by Juval Lowry (O'Reilly, 2007; ISBN: 0596526997). Check it out today at your favorite bookstore. Buy this book now.
|
|