HowTo: Using VS2010 Web.config Transformations to Bypass SSL Authentication Locally
2 min read
2 min read
Most often when you create WCF webservices you'll want to run them in a secure channel, for instance by using SSL encryption on the transport level. This makes it however cumbersome during development, when you want to host the service on your local development server.
Consequently, when testing locally you'd set the transport mode to "None" while during deploy you'd change it to "Transport" security (or one of the desired alternatives). You need to remember to change the service's configuration in the web.config however and we all know that it is easy to forget these things, not to mention our laziness ;).<system.serviceModel>When publishing using release compilation, the following transformations would be applied
<bindings>
<basicHttpBinding>
<binding name="MyService_v1_0_SOAP11Binding">
<security mode="None">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="myService_v1Behavior" name="MyCompany.MyProject.WSService.MyService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyService_v1_0_SOAP11Binding" contract="MyCompany.MyProject.WSService.MyService_v1_0">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myService_v1Behavior">
<serviceMetadata httpGetEnabled="true" externalMetadataLocation="../wsdl/MyService_v1.wsdl"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<?xml version="1.0"?>As can be seen, the security mode part is being replaced, activating Transport security.
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyService_v1_0_SOAP11Binding" xdt:Transform="Replace">
<security mode="Transport">
<transport clientCredentialType="Windows"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<!-- snip snip -->
</services>
<behaviors>
<!-- snip snip -->
</behaviors>
</system.serviceModel>
</configuration>