共用方式為


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);
}
}
image

Pros

  1. Very easy to implement.

Cons

  1. Tight coupling between router and backend.
  2. The router needs to serialize and deserialize the whole message and hence very inefficient.
  3. Any change to backend would require changes to router as well.
  4. Not a scalable solution since higher loads would choke the server due to heavy serialization issues.

 

Next – Router Implementation – Message Forwarding – Copy/Pass through