Routing with WCF
Here is sample code for routing with WCF.
Web.config for service |
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" >
<assemblies>
<add assembly="System.ServiceModel.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<serviceActivations>
<add relativeAddress="RiskManagementServiceUAT.svc" service="System.ServiceModel.Routing.RoutingService, System.ServiceModel.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</serviceActivations>
</serviceHostingEnvironment>
<services>
<!--ROUTING SERVICE -->
<service name="System.ServiceModel.Routing.RoutingService" behaviorConfiguration="routerConfig">
<endpoint address=""
binding="basicHttpBinding"
contract="System.ServiceModel.Routing.IRequestReplyRouter"
name="reqReplyEndpoint" />
</service>
</services>
<routing>
<filters>
<filter name="matchAll" filterType="MatchAll" />
</filters>
<filterTables>
<filterTable name="routingTable">
<add filterName="matchAll" endpointName="RiskService" backupList="RiskServiceBackup" />
</filterTable>
</filterTables>
<backupLists>
<backupList name="RiskServiceBackup">
<add endpointName="RiskService2"/>
</backupList>
</backupLists>
</routing>
<behaviors>
<serviceBehaviors>
<behavior name="routerConfig">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<routing routeOnHeadersOnly="false" filterTableName="routingTable" />
</behavior>
</serviceBehaviors>
</behaviors>
<client>
<!-- Define the client endpoint(s) to route messages to -->
<endpoint name="RiskService"
address="http://localhost:81/Service1.svc"
binding="basicHttpBinding"
contract="*" />
<endpoint name="RiskService2"
address="http://localhost:82/Service1.svc"
binding="basicHttpBinding"
contract="*" />
</client>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
client.config for silverlight client |
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/RiskManagementServiceUAT.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
* I updated source to make someone to understand better.
WCFRoutingServiceTest_updated.zip
* Address filter decides where to go using client's ip address. Like the sticky session under L4 load balancer, address filter ensures client to be directed to same was.
WCFRoutingServiceTest_addressfilter.zip
References:
- http://www.javierholguera.com/2012/07/18/routing-with-wcf/
- http://www.codeproject.com/Articles/423064/Getting-Started-with-WCF-Routing-Service
- http://www.codeproject.com/Articles/778575/WCF-Routing-Service-Part-III-Failover-Load-Balanci