WCF Router Service - EndPointName Filter

In our previous discussion, we discussed about the concept of routing in WCF, using the router service. You can go through the article here.

Continuing on the same lines, we will now try to understand the EndPointName filter setting as the filter type to redirect the client request to the appropriate service. We will use the same service code that we used in the previous discussion and configure the same for the use of EndPointName filter.

To start with, we will change our Routing_Service_Host application configuration. To start with, we will update the BaseAddress of the service to the following:

  1. <host>  
  2.           <baseAddresses>  
  3.             <add  baseAddress="http://localhost:5643"/>  
  4.           </baseAddresses>  
  5. </host>  
Next, we will change the endpoint settings of the router service to add the address property and update the names of the endpoint names to Svc1 and Svc2. SO the configuration will look like the following:
  1. <endpoint  
  2.                       address="/Svc1"  
  3.                       binding="wsHttpBinding"  
  4.                       name="Service_1"  
  5.                         contract="System.ServiceModel.Routing.IRequestReplyRouter"/>  
  6.   
  7. <endpoint  
  8.           address="/Svc2"  
  9.            binding="wsHttpBinding"  
  10.            name="Service_2"  
  11.            contract="System.ServiceModel.Routing.IRequestReplyRouter"/>  
Next, we will update the filterType property to EndPointName and filterData value to Service_1 and Service_2 respectively. So the routing table will look like the following:
  1. <routing>  
  2.       <filters>  
  3.         <filter name="MyFilter"  filterType="EndpointName" filterData="Service_1" />  
  4.         <filter name="MyFilter2" filterType="EndpointName" filterData="Service_2" />  
  5.       </filters>  
  6.       <filterTables>  
  7.         <filterTable name="ServiceRouterTable">  
  8.           <add filterName="MyFilter" endpointName="Service_1"/>  
  9.           <add filterName="MyFilter2" endpointName="Service_2"/>  
  10.         </filterTable>  
  11.       </filterTables>  
  12. </routing>  
So our routing service configuration is done. Now we need to update the client end point settings. Simply update the endpoint address to the following:
  1. <client>  
  2.       <endpoint address="http://localhost:5643/Svc1" binding="wsHttpBinding"  
  3.         contract="ServiceReference1.IService1" name="routingSvcEndPoint_Svc1" />  
  4.       <endpoint address="http://localhost:5643/Svc2" binding="wsHttpBinding"  
  5.         contract="ServiceReference2.IService2" name="routingSvcEndPoint_Svc2" />  
  6. </client>  
That's it, configuration is done. Run the application, enter the test values and see the results.
How it works ?

Now let's try to understand how this filter works.

To start with when we call Service1 from the client application, the system picks up the address http://localhost:5643/Svc1 from the endpoints of client application config file and call the router service. At the router service host end, it matches it's endpoint from the config file and get its name property, which is Service_1. This endpoint name is matched with the filter MyFilter with filterData value Service_1. Based on this value, the client end point with this name is selected i.e. http://localhost:65145/Service1.svc is selected and the service is executed. Similarly, this is executed for the Service_2.

Hope you enjoyed reading it. Happy coding...!!!
 
Read more articles on WCF:

 


Similar Articles