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:
<host> <baseAddresses> <add baseAddress="http://localhost:5643"/> </baseAddresses> </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:
<endpoint address="/Svc1" binding="wsHttpBinding" name="Service_1" contract="System.ServiceModel.Routing.IRequestReplyRouter"/> <endpoint address="/Svc2" binding="wsHttpBinding" name="Service_2" 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:
<routing> <filters> <filter name="MyFilter" filterType="EndpointName" filterData="Service_1" /> <filter name="MyFilter2" filterType="EndpointName" filterData="Service_2" /> </filters> <filterTables> <filterTable name="ServiceRouterTable"> <add filterName="MyFilter" endpointName="Service_1"/> <add filterName="MyFilter2" endpointName="Service_2"/> </filterTable> </filterTables> </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:
<client> <endpoint address="http://localhost:5643/Svc1" binding="wsHttpBinding" contract="ServiceReference1.IService1" name="routingSvcEndPoint_Svc1" /> <endpoint address="http://localhost:5643/Svc2" binding="wsHttpBinding" contract="ServiceReference2.IService2" name="routingSvcEndPoint_Svc2" /> </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, 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 :