Click here to Skip to main content
15,894,106 members
Articles / All Topics

WCF over HTTPS

Rate me:
Please Sign up or sign in to vote.
3.00/5 (2 votes)
19 Feb 2010CPOL 15.8K   9   1
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:
    XML
    <bindings>
      <wsHttpBinding>
         <binding name="webBinding">
           <security mode="Transport"></security>
         </binding>
      </wsHttpBinding>
    </bindings>
  2. Add the following attribute to the <endpoint> element:
    XML
    bindingConfiguration="webBinding"

That should be all.

Below is a sample <system.servicemodel>section:

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

This article was originally posted at http://nizarnoorani.com/index.php/archives/156

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) NCube, Inc.
United States United States
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.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Ramanarayanan K21-Oct-10 3:54
Ramanarayanan K21-Oct-10 3:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.