Tuesday, October 15, 2013

Rest Service Https 404 Exception

When you enable HTTPS on a rest service, very first time you will receive  404 error , and if you observe the Response text you will find the below text commented out in response body.

[EndpointNotFoundException]: There was no channel actively listening at '
https://yourdomainname/Service.svc/GetRecentProjectNotes'.
This is often caused by an incorrect address URI. Ensure that the address to which 
the message is sent matches an address on which a service  is listening.

 To fix this issue, your web.config file should contain the below lines of code.

<webHttpBinding
<binding name="webHttpBindingJsonP" maxBufferSize="2147483647"  maxReceivedMessageSize="2147483647">
<security mode="Transport">
 <transport  clientCredentialType="None"></transport>
</security>
</binding>
</webHttpBinding>

And Overall Web.Config file settings should  look like the below code.

  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp automaticFormatSelectionEnabled="true" />
          <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="123456" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <useRequestHeadersForMetadataAddress>
            <defaultPorts>
              <add scheme="https" port="443" />
            </defaultPorts>
          </useRequestHeadersForMetadataAddress>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
       <binding name="webHttpBindingJsonP" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
         <security mode="Transport">
            <transport  clientCredentialType="None"></transport>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
     <service behaviorConfiguration="ServiceBehaviour" name="SharePointMibileService.MobileService">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"  bindingConfiguration="webHttpBindingJsonP"
          contract="SharePointMibileService.IMobileService" />
      </service>
     </services>
  </system.serviceModel>