A no-code routing service using .Net 4 on IIS

A year ago I was working with Waheed Hussain who pointed out that the .Net framework includes a Routing namespace which allows you to implement a service router with zero code. Literally. It's an IIS application with no code, just a web.config. Here's an example:

< ?xml version="1.0"?>
<configuration>
	<system.serviceModel>
		<routing>
			<filters>
				<filter name="MatchAll" filterType="MatchAll" />
			</filters>
			<filtertables>
				<filtertable name="MyFilterTable">
					<add filterName="MatchAllFilter" endpointName="MyDestinationEndpoint" priority="0"/>
				</filtertable>
			</filtertables>
		</routing>

		<services>
			<service behaviorConfiguration="routingConfiguration" name="System.ServiceModel.Routing.RoutingService">
				<endpoint address="destinationUrl/" binding="basicHttpBinding" name="routerEndpoint1" contract="System.ServiceModel.Routing.IRequestReplyRouter" />
			</service>
		</services>

		<client>
			<endpoint name="MyDestinationEndpoint"
					  address="https://Destination.1.Host.com/destinationUrl/"
					  binding="basicHttpBinding"
					  bindingConfiguration="basicHttpBindingWithClientCertificate"
					  behaviorConfiguration="clientEndpointCredential"
					  contract="*" />
		</client>

		<behaviors>
			<servicebehaviors>
				<behavior name="routingConfiguration">
					<routing routeOnHeadersOnly="true" filterTableName="MyFilterTable" />
					<servicedebug includeExceptionDetailInFaults="true" />
					<servicemetadata httpGetEnabled="true"/>
				</behavior>
			</servicebehaviors>
			<endpointbehaviors>
				<behavior name="clientEndpointCredential">
					<clientcredentials>
						<clientcertificate storeName="My" 
                               storeLocation="LocalMachine" 
                               x509FindType="FindBySubjectName" 
                               findValue="MyClientCertificate" />
					</clientcredentials>
				</behavior>
			</endpointbehaviors>
		</behaviors>

		<bindings>
			<basichttpbinding>
				<binding name="basicHttpBindingWithClientCertificate">
					<security mode="Transport">
						<transport clientCredentialType="Certificate"/>
					</security>
				</binding>
			</basichttpbinding>
		</bindings>

		<!-- The clever bit - activate with no code needed -->
		<servicehostingenvironment>
			<serviceactivations>
				<add relativeAddress="Destination.1.Host.com.svc" 
             service="System.ServiceModel.Routing.RoutingService, System.ServiceModel.Routing, version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
			</serviceactivations>
		</servicehostingenvironment>
	</system.serviceModel>

	<system.web>
		<compilation debug="true" targetFramework="4.0" />
	</system.web>

	<system.net>
		<settings>
			<servicepointmanager expect100Continue="false" />
		</settings>
	</system.net>
	
</configuration>

A no-code routing service using .Net 4 o…

by Chris F Carroll read it in 2 min
0