Monday, February 11, 2008

Adventures in WCF and WF (cont.)

So, I finally had time to get things working, except the Oracle piece. I am really impressed; faster than WSE 3.0 by my calculations and easier to use.

The Architecture

Router
The heart is or starting point was best suited at the router. The custom router allows me to us WF rules in any manner I want to route incoming requests. For instance, I can for internal apps, use a custom header to by-pass security checks and router incoming requests. Then I can use another rule to route requests based on the namespace or request URL. I can take one incoming http request and route it to a tcp request. This is not much different then the sample that comes with the WCF_Card samples, just a little modification for the business need.

Here is a sample of the core code where we override the core ProcessMessage method. Here we check the rules engine for the forwarding address, then call the base interface to continue processing the message:



void ISimplexDatagramRouter.ProcessMessage(Message message)
{
EndpointAddress to = this.extension.RoutingTable.SelectDestination(message);
if (to == null)
{
message.Close();
return;
}

// If the router doesn't already have a one-way datagram channel to the 'to' EPR or if that channel is no longer opened, create one.
    ISimplexDatagramRouter forwardingChannel;

if (!this.extension.SimplexDatagramChannels.TryGetValue(to, out forwardingChannel) ((IClientChannel)forwardingChannel).State != CommunicationState.Opened)
{
lock (this.extension.SimplexDatagramChannels)
{
if (!this.extension.SimplexDatagramChannels.TryGetValue(to, out forwardingChannel) ((IClientChannel)forwardingChannel).State != CommunicationState.Opened)
{
forwardingChannel = new ChannelFactory(this.extension.Bindings[to.Uri.Scheme], to).CreateChannel();
this.extension.SimplexDatagramChannels[to] = forwardingChannel;
}
}
}

Console.WriteLine("Forwarding message " + message.Headers.Action + "...");
forwardingChannel.ProcessMessage(message);
}


Once you have this piece done, all the rules begin to make sense. So from a rules engine standpoint. I really just used the External Ruleset interface built in the samples. Again modified for the business need then recompiled for external use. Using the rules engine and this router (ask if you want the rest of the code) you see you have a very powerful utility for routing almost any type of request.

Next time I will go over the base data service which uses the latest version of the EAB.



No comments: