gpt4 book ai didi

.net - 使用 WSHttpBinding 时如何将 WCF 服务的访问限制在本地机器上?

转载 作者:行者123 更新时间:2023-12-04 04:58:47 26 4
gpt4 key购买 nike

我正在使用 WCF 在我的机器上进行进程间通信,使用 WSHttpBinding,我想限制该服务,以便只有当前机器上的进程才能调用该服务。我怎样才能做到这一点?

我更喜欢使用 NetNamedPipesBinding,它本质上会执行此限制,但是在我的场景中这是不可能的,所以我想要一种使用 WSHttpBinding 限制它的方法。我不能使用 NetNamedPipesBinding 的原因是该服务的客户端之一正在低完整性进程(保护模式下的 Internet Explorer)中运行,并且无权连接到更高完整性的命名管道(没有许多无证的jiggery-pokery like this 看起来不错,但我宁愿避免)。

一种选择是添加一个 IDispatchMessageInspector 来限制 IP 地址,如 here 所述。 .这是最好的方法吗?

更新:
该软件将部署到数百台机器上,因此使用证书之类的解决方案可能比预期的工作量更大。

最佳答案

您可以尝试使用 X509 证书来创建安全签名。这样,您就可以握住锁和 key 。其他 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 标记来声明您在与服务通信时显式使用该身份的证书。希望这可以帮助!

关于.net - 使用 WSHttpBinding 时如何将 WCF 服务的访问限制在本地机器上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7391443/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com