2011-06-01 96 views
9

我有一個WCF服務與自定義綁定,它可以在http或https上正常工作。但我完全不知道如何在http和https上使它可用?WCF與自定義綁定在http和https上

也有可能做到這一點?

這是我在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> 

感謝

+0

爲http添加一個端點,爲https添加另一個端點將解決您的問題。 – Deepesh 2011-06-01 05:20:14

+0

我已添加爲答案,但仍然收到類似這樣的錯誤「無法找到與綁定CustomBinding的端點匹配scheme https的基地址,註冊的基址地址方案爲[http]。」 – aunghn 2011-06-01 05:46:45

+1

您需要在端點中提供兩個不同的地址,因爲兩個端點不能共享相同的地址。 – Deepesh 2011-06-01 05:51:02

回答

10

你需要有兩個端點,一個用於HTTP,另一個用於HTTPS。它應該工作得很好。

<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> 
+1

感謝您的回答。但仍然無法做到這一點。當我瀏覽服務以檢查它是否正常工作時,我收到了此消息「無法找到與綁定CustomBinding的端點匹配scheme https的基地址,註冊的基地址方案爲[http]。」 – aunghn 2011-06-01 05:44:20

+0

在IIS中啓用了HTTPS嗎?如果您刪除customBindingHTTP的端點,它是否仍然有效? – carlosfigueira 2011-06-01 05:58:47

+0

是的,如果我刪除它的工作。根據你的回答,我還有一個疑問。如果網站沒有使用http或https映射,那麼我們不能將兩者都放在配置文件中。不是嗎?因爲似乎服務器不是使用http映射的,所以只能使用https瀏覽。 – aunghn 2011-06-01 06:12:55