在HTTPS情况下,HTTP.SYS未正确配置服务器证书

时间:2015-08-07 10:27:50

标签: c# wcf ssl

我需要使用第三方WCF服务。我在证书存储区配置了所需的证书,但是在调用WCF服务时遇到异常。

https://XXXX.com/AHSharedServices/CustomerServiceJAXWSController发出HTTP请求时发生错误。这可能是由于在HTTPS情况下未使用HTTP.SYS正确配置服务器证书。这也可能是由于客户端和服务器之间的安全绑定不匹配造成的。

我与服务供应商核对过,他们说他们的一切都很好,其他人已经在使用这项服务了。他们提到当请求来自我的IP地址时,他们的服务没有收到证书内容。他们将其监控到wireshark,证书的长度为0

以下是我的客户端配置。我在这里错过了什么吗?

            <?xml version="1.0" encoding="utf-8" ?>
            <configuration>
              <startup>
                <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
              </startup>
              <system.diagnostics>
                <sources>
                  <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
                    <listeners>
                      <add type="System.Diagnostics.DefaultTraceListener" name="Default">
                        <filter type="" />
                      </add>
                      <add name="ServiceModelMessageLoggingListener">
                        <filter type="" />
                      </add>
                    </listeners>
                  </source>
                </sources>
                <sharedListeners>
                  <add initializeData="D:\Log\MessageLog.svclog"
                    type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                    name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
                    <filter type="" />
                  </add>
                </sharedListeners>
                <trace autoflush="true" />
              </system.diagnostics>
              <system.serviceModel>
                <behaviors>
                  <endpointBehaviors>
                    <behavior name="endpointBehavior">
                      <clientCredentials>
                        <clientCertificate findValue="XXX.XX.com" storeName="AddressBook"
                          x509FindType="FindBySubjectName" />
                        <serviceCertificate>
                          <authentication revocationMode="NoCheck" />
                        </serviceCertificate>
                      </clientCredentials>
                    </behavior>
                  </endpointBehaviors>
                </behaviors>
                <bindings>
                  <wsHttpBinding>
                    <binding name="wsBinding">
                      <security mode="Transport">
                        <transport clientCredentialType="Certificate" />
                      </security>
                    </binding>
                  </wsHttpBinding>
                </bindings>
                <client>
                  <endpoint address="https://XXXX.com/AHSharedServices/CustomerServiceJAXWSController"
                    behaviorConfiguration="endpointBehavior" binding="wsHttpBinding"
                    bindingConfiguration="wsBinding" contract="ServiceReference1.CustomerServiceJAXWSController"
                    name="testService" />
                </client>
                <diagnostics>
                  <messageLogging logEntireMessage="true" logMalformedMessages="true"
                    logMessagesAtTransportLevel="true" logKnownPii="true"  logMessagesAtServiceLevel="true"/>
                </diagnostics>
              </system.serviceModel>
            </configuration>

3 个答案:

答案 0 :(得分:2)

我曾收到此错误,因为我的客户端使用的是TLS 1.0而不是TLS 1.2。 假设您安装了所有正确的SSL密码,您可以尝试更改使用TLS 1.2的请求。在.NET中,您可以在定义客户端后添加它:

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;

一旦我切换到TLS 1.2,错误就消失了。

答案 1 :(得分:0)

我从.CRT和.KEY生成了PFX(带有私钥的证书)并将其导入证书存储区并解决了我遇到的问题。

答案 2 :(得分:0)

在向服务器发送请求之前使用此代码:

System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    return true;
};
相关问题