WCF with custombinding on both http and https
Asked Answered
T

1

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

Theodolite answered 1/6, 2011 at 3:22 Comment(5)
adding one endpoint for http and another for https will resolve your problem.Ironwork
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]."Theodolite
you need to provide two different addresses in endpoints as two endpoints can not share same addresses.Ironwork
Were you able to resolve it? If yes, can you please post the answer?Earthen
Sample for two different addresses in endpoints ?Burge
C
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> 
Chlorine answered 1/6, 2011 at 5:18 Comment(3)
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]."Theodolite
Is HTTPS enabled in IIS? If you remove the endpoint for the customBindingHTTP, does it still work?Chlorine
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.Theodolite

© 2022 - 2024 — McMap. All rights reserved.