Configuring Your Service for Reliability
Now that you have a service up and running, making it reliable is a snap. There are three standard bindings that you can use in WCF to ensure reliability in your services. The first is
wsProfileBinding, which provides a secure, reliable, interoperable binding (based on the WS-I basic profile and WS-Reliability) suitable for simplex (i.e. one-way) service contracts. So, if you are calling a service to issue a command such as the trade scenario that was envisioned earlier, this is the way to go.
It's very simple to set it upthough unfortunately the MSDN documentation hasn't caught up with the schema in the December CTP. So, for
wsProfileBinding, you no longer use a
<wsProfileBinding> node within your
web.config, you instead keep the
<wsHttpBinding> node and add a
<reliableSession> node as shown here:
<bindings>
<wsHttpBinding>
<binding name="Binding1">
<reliableSession enabled="true"
ordered="true" />
</binding>
</wsHttpBinding>
</bindings>
It's not a good idea to rely on the MSDN documentation at the moment, because that needs to be refreshed, which will happen before release. However you'll find a huge suite of examples with the WinFX download and Windows SDK that will help you to figure out how to use the
web.config properly to ensure reliability.
Now that your service is configured for basic simplex reliability you can test it by generating a client proxy and application. Full instructions on how to do that are in the
primer article.
When you've done that, the best way to test the services is to run the client on one machine and the service on another. Call the service from the client, and ensure that it works. Then, to simulate an intermittent or problematic connection, yank the network cable from the client and call the service again. Nothing will happen, and the thread of execution will block. But plug the network cable back in, and when your network comes back online the service call will complete!
So, now you've seen how to install the WCF December CTP and build a simple service, making it send reliable messages using the Windows Communication Foundation. Best of all, the reliability characteristics are implemented for you by the framework; you don't have to do any packet monitoring or include other ugly code. This simplicity is what makes WCF a winner, and is a major factor in why WCF will be a very important developer tool for many years to come.
Reliability is essential in any business application. Using built-in WCF features, you can ensure reliability as well as the security and transactability discussed earlier in this article series. Together, these provide you with a framework to turn your software services into enterprise-class applications. Most important, you can eliminate custom coding for reliability, letting you focus on your business logic code, and not on the infrastructure and "plumbing" required by enterprise-grade systems.
The classes in the System.ServiceModel namespace do most of the work for you; you simply need to adjust the environment using the
web.config file. Remember, this is still beta technology, so it's a little rough around the edges, particularly in the mismatch between the currently documented
web.config schema and the one that works; but it is well worth investing some time and effort into to bring your skill set to the next level. The samples that come with the SDK are invaluable in this regard.