[英]How to restrict access to a WCF service to the local machine when using WSHttpBinding?
我正在使用WCF在我的機器上使用WSHttpBinding進行進程間通信,並且我想限制服務,因此只有當前機器上的進程才能調用該服務。 我怎樣才能做到這一點?
我更喜歡使用NetNamedPipesBinding,它固有地會執行此限制,但是在我的場景中這是不可能的,所以我想要一種使用WSHttpBinding來限制它的方法。 我無法使用NetNamedPipesBinding的原因是該服務的一個客戶端在低完整性進程(保護模式下的Internet Explorer)中運行,並且無權連接到更高完整性的命名管道(沒有很多無證的jiggery-pokery 像這樣看起來不錯,但我寧願避免)。
一種選擇是添加一個IDispatchMessageInspector,它按照這里描述的IP地址進行限制。 這是最好的方法嗎?
更新:該軟件將部署到數百台計算機上,因此像使用證書這樣的解決方案可能比預期更多。
您可以嘗試使用X509證書來創建安全簽名。 這樣,您可以按住鎖和鑰匙。 其他IP可以打你的服務,但不能溝通。 你可以這樣做:
在服務中:
<behaviors>
<serviceBehaviors>
<behavior name="wsHttpCertificateBehavior">
<dataContractSerializer maxItemsInObjectGraph="50000"/>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="ChainTrust" revocationMode="NoCheck" />
</clientCertificate>
<serviceCertificate findValue="CN=WSE2QuickStartServer" storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectDistinguishedName" />
</serviceCredentials>
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
在客戶端:
<behaviors>
<endpointBehaviors>
<behavior name="wsHttpCertificateBehavior">
<dataContractSerializer maxItemsInObjectGraph="50000" />
<clientCredentials>
<clientCertificate findValue="CN=WSE2QuickStartClient" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectDistinguishedName" />
<serviceCertificate>
<authentication certificateValidationMode="ChainTrust" revocationMode="NoCheck" trustedStoreLocation="LocalMachine" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="https://localhost/ClientService.svc" behaviorConfiguration="wsHttpCertificateBehavior" binding="wsHttpBinding" bindingConfiguration="ApplicationServicesBinding" contract="GAINABSApplicationServices.Contracts.ServiceContracts.IClientService" name="ClientService">
<!--<identity>
<certificateReference storeName="AddressBook" storeLocation="CurrentUser"
x509FindType="FindBySubjectName" findValue="WSE2QuickStartServer"
isChainIncluded="true" />
</identity>-->
</endpoint>
</client>
您可以選擇在客戶端上使用Identity標記來聲明您在與服務通信時明確使用身份證書。 希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.