Thursday, March 17, 2016

WCF Services : System.ServiceModel(serviceBehaviors and bindings) settings for Http and Https.

Goal

When a WCF service is converted from HTTP to HTTPS the service stops working. Here are the web.config settings. Which can fix the issue.
<!-- SERVICE MODEL -->
  <system.serviceModel>
    <behaviors>

      <serviceBehaviors>
        <!-- HTTP :  Behavior : Start -->
        <behavior name="httpBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <!-- HTTP :  Behavior : END -->
        <!-- HTTPS :  Behavior : Start -->
        <behavior name="httpsBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <useRequestHeadersForMetadataAddress />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <!-- HTTPS :  Behavior : END -->
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="httpsBinding" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"
                               minFreeMemoryPercentageToActivateService="5" />
    <bindings>
      <basicHttpBinding>
        <!-- HTTP :  Binding : Start -->
        <binding name="httpBinding" allowCookies="true" bypassProxyOnLocal="true" textEncoding="utf-8"
                 messageEncoding="Text" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None" />
        </binding>
        <!-- HTTP :  Binding : End -->

        <!-- HTTPS :  Binding : Start -->
        <binding name="httpsBinding" allowCookies="true" bypassProxyOnLocal="true" textEncoding="utf-8"
                 messageEncoding="Text" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
        <!-- HTTPS :  Binding : End -->

      </basicHttpBinding>
    </bindings>
    <services>

      <!-- HTTP :  Service : Start -->
      <service name="Sample.Service.HttpService" behaviorConfiguration="">
        <endpoint binding="basicHttpBinding" bindingName="" bindingConfiguration="httpBinding"
                  contract="Sample.Service.Interface.IHttpService" address="" name="" />
      </service>
      <!-- HTTP :  Service : End -->

      <!-- HTTPS :  Service : Start -->
      <service name="Sample.Service.HttpsService" behaviorConfiguration="">
        <endpoint binding="basicHttpBinding" bindingName="" bindingConfiguration="httpsBinding"
                  contract="Sample.Service.Interface.IHttpsService" address="" name="" />
      </service>
      <!-- HTTPS :  Service : End -->
    </services>
  </system.serviceModel>
  <!-- SERVICE MODEL -->

No comments:

Post a Comment