10

I have a WCF service with custombinding and it is working fine on either http or https. But I have totally no idea about how can I make it available on both http and https?

Also is it possible to do that?

Here's my configuration in web.config.

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<behaviors>
    <serviceBehaviors>
        <behavior name="">
            <serviceMetadata httpsGetEnabled="true" />                    
            <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>         
    </serviceBehaviors>
</behaviors>
<bindings>
    <customBinding>                     
        <binding name="customBinding0">
          <binaryMessageEncoding />
          <httpsTransport />
        </binding>
    </customBinding>
</bindings>
<services>
    <service name="MyWCFService">                           
        <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
            contract="MyWCFService" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    </service>      
</services>

Thanks

aunghn
  • 165
  • 1
  • 1
  • 9
  • adding one endpoint for http and another for https will resolve your problem. – Deepesh Jun 01 '11 at 05:20
  • I've added as an answer, but still got the error like this "Could not find a base address that matches scheme https for the endpoint with binding CustomBinding. Registered base address schemes are [http]." – aunghn Jun 01 '11 at 05:46
  • 1
    you need to provide two different addresses in endpoints as two endpoints can not share same addresses. – Deepesh Jun 01 '11 at 05:51
  • Were you able to resolve it? If yes, can you please post the answer? – LCJ Dec 06 '12 at 10:59
  • Sample for two different addresses in endpoints ? – Kiquenet Mar 19 '19 at 12:13

1 Answers1

12

You'll need to have two endpoints, one for HTTP and another for HTTPS. It should work just fine.

<bindings>
    <customBinding>
        <binding name="customBindingHTTP">
            <binaryMessageEncoding />
            <httpTransport />
        </binding>
        <binding name="customBindingHTTPS">
            <binaryMessageEncoding />
            <httpsTransport />
        </binding>
    </customBinding>
</bindings>
<services>
    <service name="MyWCFService">
        <endpoint address=""
                  binding="customBinding"
                  bindingConfiguration="customBindingHTTP"
                  contract="MyWCFService" />
        <endpoint address=""
                  binding="customBinding"
                  bindingConfiguration="customBindingHTTPS"
                  contract="MyWCFService" />
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
    </service> 
</services> 
carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
  • 2
    Thanks for your answer. But still not able to do this. When I browse the service to check whether it is working, I got this message "Could not find a base address that matches scheme https for the endpoint with binding CustomBinding. Registered base address schemes are [http]." – aunghn Jun 01 '11 at 05:44
  • Is HTTPS enabled in IIS? If you remove the endpoint for the customBindingHTTP, does it still work? – carlosfigueira Jun 01 '11 at 05:58
  • Yes it's working if i remove. I have one more doubt according to your answer. If website is not map with either http or https, at that time we can not put both in the config file. Isn't it? Because seems like the server is not map with http, it can only be browsed with https. – aunghn Jun 01 '11 at 06:12