首先,這兩種方法都是安全的,就足夠了病例的90%。傳輸安全保護您的通信渠道,但不會加密您的實際信息。消息安全性會加密您的實際消息,因此消息傳遞的服務器無法看到消息內容,並且需要私鑰才能解密消息。所以人們可能會認爲消息安全性更安全,至少它更適合用於互聯網通信。在WCF安全一些好的鏈接: Message Security in WCF和patterns & practices Improving Web Services Security Guide
netTcpBinding
使用傳輸安全默認情況下,但是,這並不意味着你不能使用郵件安全吧。傳輸安全性比Message安全性(每個消息被加密)的計算開銷少,因此它具有更好的性能。使用netTcpBinding
在互聯網上的一個需要注意的是,它可能不能保證在任何時候都工作(在過去我有successfully
成立netTcpBinding
在互聯網上雖然),因爲它使用了一些端口使用並不總是保證是消息傳輸留下的網絡路由器和防火牆(在互聯網上,你的消息將經歷許多路由器和防火牆)。對於互聯網通訊暢通,考慮HTTP綁定,例如basicHttpBinding
或wsHttpBinding
也支持信息安全的一個。
您可以在其他綁定使用信息的安全性,如:
<netTcpBinding>
<binding name="securedBinding">
<security mode="Message">
</security>
</binding>
</netTcpBinding>
,然後設置你的端點bindingConfiguration
到。
和託管服務(服務器)的機器上:
<behavoirs>
<serviceBehavior>
<behavior name="securityBehaviour">
<serviceCredentials>
<serviceCertificate
findValue="serviceCert"
storeLocation="LocalMachine"
storeName="My"
x509FindType="FindBySubjectName" />
</serviceCredentials>
</behavoir>
</serviceBehavior>
</behavoirs>
<services>
<service name="Service1" behaviorConfiguration="securityBehaviour">
<endpoint address="" binding="netTcpBinding" contract="IService1" bindingConfiguration="securedBinding">
</endpoint>
</service>
</services>
如果有限的客戶,你知道他們是誰,你可以使用自簽名的證書。但是,如果您想要許多未知客戶端使用您的服務時獲得最佳安全性,則最好從已知的CA中購買一個客戶端。然後您需要在服務器上安裝服務器證書。 Here是關於如何使用證書保護您的服務的文章,博客還提供了一些您可能想要閱讀的其他有用的WCF安全性文章。
非常感謝你。 –