繁体   English   中英

使用WSHttpBinding时如何限制对本地计算机的WCF服务的访问?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM