0

I have a REST service. This service need to be work with http and https. I've tried to add two endpoint in my web.config file. But i get this error when i try to browse my service over http:

Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http].

and i get this error when i try to browse over https:

Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are [https].

If i remove one of endpoint from my config file, the both http and https services works fine. I checked this link: WebHttpBinding with Http and Https But when i remove endpoints from my config file, the both http and https services runs without any errors on web browser. But when i try to call one of my methods (over a rest client tool) in this service it gets:

500 Internal Server Error.

How can i run this service over http and https without any errors?

My config file is like this:

 <system.serviceModel>
<protocolMapping>
  <add scheme="http" binding="webHttpBinding" bindingConfiguration="webHttpBinding"/>
  <add scheme="https" binding="webHttpBinding" bindingConfiguration="webHttpsBinding"/>
</protocolMapping>
<bindings>
  <webHttpBinding>
    <binding name="webHttpBinding">
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None" />
      </security>
    </binding>
    <binding name="webHttpsBinding">
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None" />
      </security>
    </binding>
  </webHttpBinding>
</bindings>
<services>
  <service name="MyProject.MyService" behaviorConfiguration="serviceBehavior">
    <endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" bindingConfiguration="webHttpBinding" contract="MyProject.IMyService" />
    <endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" bindingConfiguration="webHttpsBinding" contract="MyProject.IMyService" />
    <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />-->
    <!--<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>-->
  </service>
</services> 
<behaviors>
  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <serviceAuthorization serviceAuthorizationManagerType="MyProject.RestAuthorizationManager, MyProject"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>    

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>     
    <directoryBrowse enabled="true"/>
  </system.webServer>
Community
  • 1
  • 1

1 Answers1

0

here is a sample web.config in order to have both http and https support. i hope solve your problem:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
  </system.web>

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="SoapBinding" />
      </basicHttpBinding>
      <basicHttpsBinding>
        <binding name="SecureSoapBinding" />
      </basicHttpsBinding>

      <webHttpBinding>
        <binding name="RestBinding" />
        <binding name="SecureRestBinding">
          <security mode="Transport" />
        </binding>
      </webHttpBinding>

      <mexHttpBinding>
        <binding name="MexBinding" />
      </mexHttpBinding>
      <mexHttpsBinding>
        <binding name="SecureMexBinding" />
      </mexHttpsBinding>
    </bindings>

    <client />

    <services>
      <service behaviorConfiguration="ServiceBehavior" name="Interface.Core">
        <endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="SoapBinding" name="Soap" contract="Interface.ICore" />
        <endpoint address="soap" binding="basicHttpsBinding" bindingConfiguration="SecureSoapBinding" name="SecureSoap" contract="Interface.ICore" />
        <endpoint address="" behaviorConfiguration="Web" binding="webHttpBinding" bindingConfiguration="RestBinding" name="Rest" contract="Interface.ICore" />
        <endpoint address="" behaviorConfiguration="Web" binding="webHttpBinding" bindingConfiguration="SecureRestBinding" name="SecureRest" contract="Interface.ICore" />
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="MexBinding" name="Mex" contract="IMetadataExchange" />
        <endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration="SecureMexBinding" name="SecureMex" contract="IMetadataExchange" />
      </service>
    </services>

    <behaviors>
      <endpointBehaviors>
        <behavior name="Web">
          <webHttp helpEnabled="true" defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" />
        </behavior>
      </endpointBehaviors>

      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="false" />
  </system.webServer>

</configuration>
Mohammad
  • 2,724
  • 6
  • 29
  • 55