简体   繁体   English

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

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

I have a WCF self-hosted service that is accessed over a VPN by client applications.我有一个 WCF 自托管服务,客户端应用程序通过 VPN 访问该服务。 This works in most cases, but some clients are unable to find the server by the DNS name.这在大多数情况下都有效,但有些客户端无法通过名称 DNS 找到服务器。 I want to configure it so that the IP address is specified as well.我想对其进行配置,以便也指定 IP 地址。 I cannot simply use the server's IP address instead of the server name in the client config because then it fails the security check because the remote endpoint provides a DNS claim of its server name.我不能简单地使用服务器的 IP 地址而不是客户端配置中的服务器名称,因为这样它就无法通过安全检查,因为远程端点提供了其服务器名称的 DNS 声明。 I could replace the server certificate with one specifiying the IP address as the subject name, but my understanding is that this would not work either.我可以用将 IP 地址指定为主题名称的证书替换服务器证书,但我的理解是这也行不通。

How can I change the configuration so that the client can find the service by its Ip address while still using the server name for its identity?我如何更改配置,以便客户端可以通过其 Ip 地址找到服务,同时仍然使用服务器名称作为其身份?

Service configuration:服务配置:

...
   <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>

Client configuration:客户端配置:

<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>

but some clients are unable to find the server by the DNS name但有些客户端无法通过 DNS 名称找到服务器

You can resolve this issue by reviewing the Troubleshooting Domain Name System (DNS) issues document.您可以通过查看域名系统 (DNS) 问题故障排除文档来解决此问题。

You can try the following methods, see this post for details您可以尝试以下方法,详情请看这篇文章

1.) Add the IP to the endpoint address & add a host name with the base IP address like so: 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.) If you have a domain name ( www.myDomain.com ) then add this to the host header in IIS. 2.) 如果您有域名 ( www.myDomain.com ),则将其添加到 IIS 中的主机 header。
3.) Add the IP address & computer name to the clients hosts file (easy fix not always possible to get all of your clients to add this to their host file however) 3.) 将 IP 地址和计算机名称添加到客户端主机文件中(然而,简单的修复并不总是能够让所有客户端将其添加到他们的主机文件中)

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

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