Search code examples
wcfrestsslweb-configwcf-binding

SSL implementation for WCF Rest Service


 <system.serviceModel>
 <!--WCF Service-->
 <services>
  <service name="Service.RestServices">
    <endpoint address=""
              binding="basicHttpBinding"
              bindingConfiguration="secureHttpBinding"
              contract="Service.IRestServices"/>

    <endpoint address="mex"
              binding="mexHttpsBinding"
              contract="Service.IRestServices" />
  </service>
 </services>
 <!--WCF Binding-->
 <bindings>
  <basicHttpBinding>
    <binding name="secureHttpBinding">
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding>
 </bindings>
 <!--WCF Behaviors--> 
 <behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpsGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
 </behaviors>    

Is there anything else I want to consider in my Web.config file? Below is my service interface.

Service Interface(IRestServices)

[OperationContract] [WebInvoke(ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, Method = "POST", UriTemplate = "Login", BodyStyle = WebMessageBodyStyle.Wrapped)]

When I am try to call using HTTPS then response I get is 404(Not Found), while using HTTP, I am getting response data properly.

How can I call my rest api web service(WCF) using HTTPS ?


Solution

  • We have to define factory in our WebService.svc file to support Https in WCF rest service

    <%@ ServiceHost Language="C#" Debug="true" Service="XcellenceIt.Plugin.Misc.NopRestApi.Service.RestServices" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>