2011-12-29 108 views
2

如何確保我的WCF服務已通過HTTPS並且所有通信均通過HTTPS?強制WCF使用HTTPS

在服務我的web.config文件

即使世界沒什麼可說的http:// ...或https:// ....

HTTPS是在IIS中設置,我可以訪問Web服務通過http和https。

或者,如果使用消息級別的安全性進行加密,這不是必需的嗎?

<bindings> 
    <wsHttpBinding> 
    <binding name="Binding1" maxReceivedMessageSize="20000000"> 
     <security mode="Message"> 
     <message clientCredentialType="UserName"/> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

回答

2

HTTPS是基於傳輸層安全性(TLS)的HTTP。要啓用它,你需要配置你的綁定,除了現有的消息級安全使用傳輸安全機制:

<bindings> 
    <wsHttpBinding> 
    <binding name="Binding1" maxReceivedMessageSize="20000000"> 
     <security mode="TransportWithMessageCredential"> 
     <message clientCredentialType="UserName"/> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 
+0

謝謝,根據@Vano Maisuradze的回答,是否必須將''更改爲''?這似乎工作。 – Marcus 2011-12-29 14:53:38

+0

這隻會改變您的服務本身(網絡服務位),而不會改變元數據交換或用戶瀏覽服務發現頁面的功能(當您在瀏覽器中轉到http://domain/myservice.svc時)。如果這些必須通過HTTPS工作,您需要進一步,如Vano所述。 – 2011-12-29 15:04:34

1

這裏是HTTPS配置:

<services> 
    <service name="WcfTransport.Service1" behaviorConfiguration="MyHttpsBehaviour"> 
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="TransportSecurityBinding" contract="WcfTransport.IService1"/> 
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 

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

<bindings> 
    <wsHttpBinding> 
    <binding name="TransportSecurityBinding"> 
     <security mode="Transport"> 
     <transport clientCredentialType="Windows"></transport> 
     </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 

注意httpsGetEnabled設置爲true和httpGetEnabled設置爲false。如果您不需要元數據交換,也可以刪除mex端點。

p.s.消息安全性用於消息加密,但當然,您可以使用https使用消息安全性。

+0

所以只是做''品牌它通過HTTPS?它似乎工作,但我現在不確定基於@Programming Hero的回答 – Marcus 2011-12-29 14:52:56

+0

是的。它只接受https請求。您也可以在IIS中刪除http綁定並僅添加https綁定。 – 2011-12-29 15:26:47