65.9K
CodeProject is changing. Read more.
Home

WCF over HTTPS

starIconstarIconstarIconemptyStarIconemptyStarIcon

3.00/5 (2 votes)

Feb 19, 2010

CPOL
viewsIcon

15938

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:

  1. Add the following inside the <system.servicemodel> section:
    <bindings>
      <wsHttpBinding>
         <binding name="webBinding">
           <security mode="Transport"></security>
         </binding>
      </wsHttpBinding>
    </bindings>
  2. Add the following attribute to the <endpoint> element:
    bindingConfiguration="webBinding"

That should be all.

Below is a sample section:

<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>

Post to Twitter Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to Reddit Reddit Post to StumbleUpon