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