- 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.
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:
<add verb="*" path="*.asmx"
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" ?>
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
// 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.
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:
<add verb="*" path="*.asmx"
type="CBRouter.CBRoutingHandler, CBRouter" />
Other Resources & Links:
Routing SOAP Messages with WSE
How to: Configure the WSE SOAP Router
How to: Route SOAP Messages Based Upon Their Content