Wednesday, October 8, 2008

ESB: WCF implementation

So, at first, in order to implement enterprise service using WCF, we need the idea of generic service, which can handle any incoming messages.
This blog describes how to handle generic messages in WCF service.
This means, that we can serialize any custom serializable object and send it as message to WCF service and service will accept it and will try to process.

But whats next? The question is, how would WCF service know how to process this incoming message.... It can be, for instance business logic related entity or notification about problems in remote component...
Yes, and according to title our WCF service needs to be generic. The idea below describes quite simple WCF service that can handle various incoming messages without any recompilation.
The flow is the following:
1. Retrieve contents of body element
2. Based on some criteria (it can be name of the root node plus namespace name), choose XSLT transformation that is appropriate for given message. XSLT transformation file can be stored as local file or in database.
3. Using XSLT transformation transform incoming XML to XAML (or even to c# code!).
4. Compile resulting XAML.
5. Execute compiled code. The resulting code can do anything: from executing database queries to sending e-mail to administrator

Drawbacks of this approach:
1. You are not able to debug the resulting code
2. It requires a nice tool that would produce XSLT transformation based on given message content and handler (c# code).

1. As new messages are introduced in enterprise, you do not have to modify/redeploy the service. All you need, is to provide WCF service with additional scripts.
2. It is very flexible, because you are not dependent on any message types, so you theoretically can receive and process anything.


Yes, I know, instead of XSLT transformation we can deploy assemblies-handlers for each event and dynamically load these assemblies.

Probably, this approach will never get a chance to be implemented... I just wanted to share interesting idea...

No comments: