Yanshof
Yanshof

Reputation: 9926

how to make wcf working web service to work on https ?

I wrote some wcf web service that work good ( restful ). I need now to support the calling of those web service only from https

The configuration file code:

 <service name="Microsoft.ServiceModel.Samples.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">  
    <host>  
      <baseAddresses>  
        <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>  
      </baseAddresses>  
    </host>  
    <endpoint address=""    binding="wsHttpBinding" contract="Microsoft.ServiceModel.Samples.ICalculator" />  
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />  
  </service>  
</services>  
<behaviors>  
  <serviceBehaviors>  
    <behavior name="CalculatorServiceBehavior">  
      <serviceMetadata httpGetEnabled="true"/>  
      <serviceDebug includeExceptionDetailInFaults="False"/>  
    </behavior>  
  </serviceBehaviors>  
</behaviors>  

Upvotes: 0

Views: 39

Answers (1)

Navoneel Talukdar
Navoneel Talukdar

Reputation: 4588

Here are the steps with which you can enable SSL.

  • First create a self signed certificate,You can use IIS manager to do it.
  • Open INETMGR and then open Server Certificates then proceed to create self signed certificate,say the name is testcertificate.

Now in your wcf configuration file would be like this

<system.serviceModel>
    <services>
      <service name="NorthwindServices.ProductService">

        <endpoint address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="secureHttpBinding"
                  contract="NorthwindServices.IProducts"/>

        <endpoint address="mex"
                  binding="mexHttpsBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="secureHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>      
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>          
          <serviceMetadata httpsGetEnabled="true"/>          
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>  

Note I have changed below things

1) In serviceBehaviors for allowing https request I set httpsGetEnabled="true".

2) Set clientCredentialType as None to specify anonymous authentication which does not perform client authetication. The possible values for clientCredentialType are None, Basic, Digest, Ntlm, Windows.

Finally you can host the service in IIS.

In IIS right click on the site and click on Edit Bindings,Now click on Add button and select https from type dropdown of Add Site Binding window. From SSL Certificate drop down select testcertificate which you created in first step. Click Ok and close Site Bindings window.

enter image description here

Publish wcf in localhost.

enter image description here

Upvotes: 1

Related Questions