Exam 70-554 - Route SOAP messages by using a WSE router.

Section 1

  • Part 3
    • Topic 6

Route SOAP messages by using a WSE router.

  • Create a WSE router application.
  • Configure a WSE router application.
  • Configure a referral cache for routing.

Summary

Another nice feature of WSE is the ability to configure a server as a router for SOAP messages. By setting up a server as a router, you can separate the end point publication from the server that actually runs the service and sends requests and responses. This would enable you to easily change the destination server without down time. You need only change where requests are routed in the referral cache.

To configure a server as a router, you must do two things. First you have to configure an http handler to redirect requests to the webservices you want to route to the SoapHttpRouter type. request paths can include wildcards. An example of setting up the httphandler from msdn is below:

<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*.asmx"
type="Microsoft.Web.Services3.Messaging.SoapHttpRouter,
Microsoft.Web.Services3, Version=3.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
</httpHandlers>
</system.web>
</configuration>

Once you have the handler configured you must configure a referral cache to tell the handler how to route the requests. You do this by adding a microsoft.web.services3 node to the config sections at the top of the web config and then define a referral node in the actual microsoft.web.services3 node located later in the config file.

Within the referral node you add a cache element that points to the referralCache config file that defines the routing policy. If you need to change the referral policy you would typically just alter the file that this config was pointing to.

In the actual referralCache config file you declare a r:ref node for every routing instruction you want to define. Each ref has a r:for node that contains how messages are matched to this instruction (r:exact for exact match, r:prefix for a prefix). They also have a r:if node for using an conditionals like (r:ttl time to live). They also have a r:go node that can define where to route the matching requests. They can also have a r:refId node to define the unqiue identifier for the instruction. The following sample is from msdn:

<?xml version="1.0" ?>
<r:referrals
xmlns:r="http://schemas.xmlsoap.org/ws/2001/10/referral">
<r:ref>
<r:for>
<r:exact>
http://www.contoso.com/MyWebApplication/SumService.asmx
</r:exact>
</r:for>
<r:if/>
<r:go>
<r:via>
http://www.cohowinery.com/MyWebApplication/SumService.asmx
</r:via>
</r:go>
<r:refId>uuid:fa469956-0057-4e77-962a-81c5e292f2ae</r:refId>
</r:ref>
</r:referrals>

If you want to route messages based on content you can create your own custom class that inherits from SoapHttpRouter. In this class you would need to override the ProcessRequestMessage method and provide a custom implementation that returns the url of the web service to route the message to. An example implementation from msdn is below:

protected override Uri ProcessRequestMessage(SoapEnvelope message)
{
XmlNodeList headersMatched = message.Header.GetElementsByTagName(PremiumHeaderName, PremiumNamespaceUri);
if (headersMatched.Count == 0)
{
// Defer to the WSE RoutingHandler's implementation
return base.ProcessRequestMessage(message);
}
else
{
// Add your custom code here that adds a new via. By adding a
// a via element that specifies the endpoint of the premium
// service, the SOAP message is sent to the premium
// service instead of the standard service.
return premiumServiceUri;
}
}

To configure your router to use your custom router you must configure the httphandler to pass requests to it. An example configuration from msdn is below:

<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="*.asmx"
type="CBRouter.CBRoutingHandler, CBRouter" />
</httpHandlers>
</system.web>
</configuration>

Other Resources & Links:

Routing SOAP Messages with WSE
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wse3.0/html/4344d43e-ceb4-43a9-8f8c-6a3f89f786bd.asp

How to: Configure the WSE SOAP Router
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wse3.0/html/6414f229-cead-48af-a293-cb893c24c0e6.asp

How to: Route SOAP Messages Based Upon Their Content
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wse3.0/html/6414f229-cead-48af-a293-cb893c24c0e6.asp

Avanade Expert #56

Being Deaf in One Ear