Escape the Routing Apocalypse with WCF 4!

March 7, 2011 at 10:15 am | Posted in Microsoft | Leave a comment
Tags: , , , ,

Since the 70-513 practice exam has just rolled off the press here at Transcender, I thought it might be a good idea to go over some of the new WCF features in .NET 4. As reported previously, the topics covered by the 70-513 exam are eerily similar to the .NET 3.5 version. The addition of jQuery and JSON is hardly surprising, because these topics are also covered in the 70-515 exam. But considering the undead possibilities in popular movie and game culture,  there are some useful additions to the .NET Framework 4 that do merit some discussion.

WCF Routing in a Zombie Apocalypse

WCF Routing in a Zombie Apocalypse

One of these features is message routing. Although WCF has always offered a robust message filtering framework that supports XPath 1.0 queries and SOAP headers, actually routing messages based on these message filters has required manual implementation. In WCF 4.0, an automated Routing Service is provided to reduce developer effort and support message body content.

To demonstrate this difference, let’s look at a typical business scenario. Take a large, sprawling campus that requires WCF for mission-critical messages, such as a biomedical research group with four facilities: Downtown, Uptown, College, and Rural Lab. If a scientist at the Uptown office needed to send a virus report on potential combat agents to the College office, client A will need to specify the WCF endpoint at College. If, however, that same scientist must send another report on fungal antibodies to the Rural Lab location, then another endpoint will be required. If we wanted to route these messages through the headquarters at the Downtown facility, then in .NET 3.5, we would need to develop a specialized intermediary service with all of the route plumbing, not to mention the impact of an extreme communication failure like a widespread power outage, crippling protest riots, or even a zombie apocalypse. How would messages warning of an approach of the walking dead be handled so as to avoid cataclysmic consequences?

Enter the Routing Service in .NET 4. The Routing Service provides a generic mechanism to direct any SOAP messages to specified endpoints using features such as service aggregation and versioning, and priority and multicast routing. The Routing Service sends and receives messages at a designated endpoint and routes the message exchange between specified sources and destinations automatically. The only thing you have to do is specify the logical route.

In our scenario, the Routing Service at the downtown headquarters could could provide the following endpoints:

<!– Primary endpoint of Downtown Headquarters –>
<endpoint name=”DowntownReport” address=”http://Main/Reports/DiseaseReport&#8221;
binding=”wsHttpBinding” contract=”IDiseaseReport” />
<!– Other service endpoints –>
<endpoint name=”Uptown” address=”http://Uptown/Reports/DiseaseReport&#8221;
binding=”wsHttpBinding” contract=”IDiseaseReport” />
<endpoint name=”College” address=”http://College/Reports/DiseaseReport&#8221;
binding=”wsHttpBinding” contract=”IDiseaseReport” />
<endpoint name=”RuralLab” address=”http://RuralLab/Reports/DiseaseReport&#8221;
binding=”wsHttpBinding” contract=”IDiseaseReport” />

Rather than being aware of the specific endpoint, the WCF client can specify the desired destination in a SOAP header. Based on factors like message values and priority, the message is forwarded onto the appropriate endpoint. For example, the filtering could be configured as follows:

<filter name=”UptownFilter” filterType=”XPath”
filterData=”/s12:Envelope/s12:Header/custom:Destination=Uptown” />
<filter name=”RuralLabFilter” filterType=”XPath”
filterData=”/s12:Envelope/s12:Header/custom:Destination=RuralLab” />
<filter name=”CollegeFilter” filterType=”XPath”
filterData=”/s12:Envelope/s12:Header/custom:Destination=College” />
<filter name=”DowntownFilter” filterType=”MatchAll” />
<table name=”mainTable”>
<add FilterName=”UptownFilter” priority=”2″ />
<add FilterName=”CollegeFilter” priority=”2″ />
<add FilterName=”RuralLabFilter” priority=”2″ />
<add FilterName=”GenericFilter” priority=”1″ />

Using the declared filter table, WCF messages that specify destinations are directed to their respective locations, while all other messages are directed to the default service endpoint at the downtown headquarters. So, if one location goes out, the filter can be altered and messages from WCF clients can be re-routed without service interruption.  All of this is provided with only minimal configuration and no development effort whatsoever. Just because a mob of zombies looms on the horizon, there is no reason you have to work like one!

–Joshua Hester

Leave a Comment »

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Entries and comments feeds.

%d bloggers like this: