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>section:
<system.serviceModel>
<services>
<service name="MyWebService"
behaviorConfiguration="ServiceBehavior">
<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>
Reddit
Nizar Noorani is an independent software consultant. He provides services in the areas of web applications and systems architecture, analysis, design and development. Although proficient in a variety of technologies, he specializes in the .NET technology. He can be reached at nizar.noorani@gmail.com.