4

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

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

一种选择是添加一个 IDispatchMessageInspector,它按此处所述的 IP 地址进行限制。这是最好的方法吗?

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

4

1 回答 1

0

您可以尝试使用 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>

您可以选择需要客户端上的身份标签来声明您在与服务通信时明确使用证书作为身份。希望这可以帮助!

于 2011-09-12T17:31:40.883 回答