繁体   English   中英

在使用服务证书的WCF客户端配置中指定IP服务地址

[英]Specify IP address of service in WCF client configuration where service certificate is used

我有一个 WCF 自托管服务,客户端应用程序通过 VPN 访问该服务。 这在大多数情况下都有效,但有些客户端无法通过名称 DNS 找到服务器。 我想对其进行配置,以便也指定 IP 地址。 我不能简单地使用服务器的 IP 地址而不是客户端配置中的服务器名称,因为这样它就无法通过安全检查,因为远程端点提供了其服务器名称的 DNS 声明。 我可以用将 IP 地址指定为主题名称的证书替换服务器证书,但我的理解是这也行不通。

我如何更改配置,以便客户端可以通过其 Ip 地址找到服务,同时仍然使用服务器名称作为其身份?

服务配置:

...
   <bindings>
        <customBinding>
            <binding name="gzipBinding">
                <gzipMessageEncoding />
                <sslStreamSecurity />
                <tcpTransport>
                </tcpTransport>
            </binding>
        </customBinding>
        <wsHttpBinding>
            <binding name="ClientCertAuthenticationBinding">
                <security mode="Message">
                    <message clientCredentialType="Certificate"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>

    <services>
        <service name="MyServices.HandshakeService" behaviorConfiguration="HandshakeServiceBehavior">
            <host>
                <baseAddresses>
                <add baseAddress="http://10.0.0.4:8000/Handshake"/>
                </baseAddresses>
            </host>
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="ClientCertAuthenticationBinding" contract="OCS.Client.KnownLayer.IHandshaker"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>

    <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
    <behaviors>
        <serviceBehaviors>
            <behavior name="HandshakeServiceBehavior">
                <serviceMetadata httpGetEnabled="True"/>
                <serviceDebug includeExceptionDetailInFaults="True"/>
                <serviceCredentials>
                    <serviceCertificate findValue="MyServiceComputerName" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
                    <clientCertificate>

                        <!-- <authentication certificateValidationMode="Custom" customCertificateValidatorType="Rdt.CertificateIdentification.ClientAuthentication.MyX509CertificateValidator, OCS"/>-->
                        <!-- The custom validator replicates the chaintrust functionality and extends it with a check against the identity database-->
                        <authentication certificateValidationMode="ChainTrust" revocationMode="NoCheck"/>
                    </clientCertificate>
                </serviceCredentials>

            </behavior>
        </serviceBehaviors>
    </behaviors>

客户端配置:

<system.serviceModel>

    <client>
        <endpoint address="http://MyServiceComputerName:8000/Handshake" binding="wsHttpBinding" behaviorConfiguration="ClientCertificateBehavior"
      bindingConfiguration="WSHttpBinding_IHandshaker" contract="IHandshaker"
      name="WSHttpBinding_IHandshaker"/>
    </client>

    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IHandshaker">
                <security>
                    <message clientCredentialType="Certificate" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>

    <behaviors>
        <endpointBehaviors>
            <behavior name="ClientCertificateBehavior">
                <clientCredentials>
                    <clientCertificate findValue="MyClientCert" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
                    <serviceCertificate>
                        <authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck"/>
                    </serviceCertificate>
                </clientCredentials>
            </behavior>
        </endpointBehaviors>
    </behaviors>
</system.serviceModel>

但有些客户端无法通过 DNS 名称找到服务器

您可以通过查看域名系统 (DNS) 问题故障排除文档来解决此问题。

您可以尝试以下方法,详情请看这篇文章

1.) 将 IP 添加到端点地址并添加一个主机名,其基本地址为 IP,如下所示:

<endpoint
  address="http://xx.xx.xx.xx/ServiceApp/Service.svc"
  binding="basicHttpBinding" contract="IService">
</endpoint>
<host>
  <baseAddresses>
    <add baseAddress="http://xx.xx.xx.xx/ServiceApp/" />
  </baseAddresses>
</host>

2.) 如果您有域名 ( www.myDomain.com ),则将其添加到 IIS 中的主机 header。
3.) 将 IP 地址和计算机名称添加到客户端主机文件中(然而,简单的修复并不总是能够让所有客户端将其添加到他们的主机文件中)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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