WCF over HTTPS





3.00/5 (2 votes)
When deploying a WCF web service over HTTPS, you must set the ‘Security’ mode to Transport.
I have been working on a WCF web service that I finally deployed to our staging server which runs over HTTPS. Everything seemed fine. I was able to hit it and generate the WSDL. However, when I tried running the svcutil.exe on it, I got the following error:
Error: Cannot add the transport element 'httpTransport'. Another transport eleme
nt already exists in the binding 'System.ServiceModel.Configuration.HttpTranspor
tElement, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=
b77a5c561934e089'. There can only be one transport element for each binding.
Upon investigation, I realized that when deploying a WCF web service over HTTPS, you must set the ‘Security
’ mode to ‘Transport
.’. Below are the steps to do this:
- Add the following inside the
<system.servicemodel>
section:<bindings> <wsHttpBinding> <binding name="webBinding"> <security mode="Transport"></security> </binding> </wsHttpBinding> </bindings>
- Add the following attribute to the
<endpoint>
element:bindingConfiguration="webBinding"
That should be all.
Below is a sample
<system.serviceModel>
<services>
<service name="MyWebService"
behaviorConfiguration="ServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="" binding="wsHttpBinding"
bindingConfiguration="webBinding" contract="IMyWebService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="webBinding">
<security mode="Transport" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>