Router Implementation – Strong Typed with Message Forwarding
I use the term broker and router very loosely here since they follow very similar guidelines as described here - WCF Broker Overview. Apologies for not being very rigid with these terms.
I will dive into best practices of building a router by progressing from a very simple implementation to a robust one through different scenarios and varying degrees of complexities.
The easiest implementation is by using a strongly typed contract with message forwarding as shown below.
[ServiceContract]
public interface IOrderService
{
[OperationContract]
Order[] GetOrders(int numOrders);
}
class OrderService:IOrderService
{
Order[] GetOrders(int numOrders)
{
return backendProxy.GetOrders(numOrders);
}
}
Pros
- Very easy to implement.
Cons
- Tight coupling between router and backend.
- The router needs to serialize and deserialize the whole message and hence very inefficient.
- Any change to backend would require changes to router as well.
- Not a scalable solution since higher loads would choke the server due to heavy serialization issues.
Next – Router Implementation – Message Forwarding – Copy/Pass through