1

我正在使用第三方 wsdl 连接到服务。我已获得安全证书和用户名/密码。

我有:

  • 在我的 Windows 7 机器上安装了证书
  • 确保它具有正确的权限
  • 将 API 的正确位置存储在 web.config 中

代码每次都失败。错误消息会发生变化,但它们包括:

  • 身份验证失败,因为远程方已关闭传输流。
  • 现有连接被远程主机强行关闭
  • 无法创建 SSL/TLS 安全通道

这是我正在执行的代码:

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;

//Third party client
var client = new ConnectionPortClient();

//Including these two lines or not does not affect the outcome
//client.ClientCredentials.UserName.UserName = "username";
//client.ClientCredentials.UserName.Password = "password";

client.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(@"C:\..\cert.p12", "password", X509KeyStorageFlags.MachineKeySet);

var results = client.getResults("");

这是 web.config 的相关部分:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="assessmentBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
            receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
            bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="Transport">
            <transport clientCredentialType="None" proxyCredentialType="None"
                realm="" />
            <message clientCredentialType="Certificate" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://endpoint/" binding="basicHttpBinding"
          bindingConfiguration="assessmentBinding" contract="API.Assessment"
          name="assessmentSOAP" />
    </client>
  </system.serviceModel>

对这里发生的事情有任何想法吗?

4

1 回答 1

2

您使用证书消息凭据类型,但您尝试为用户名消息凭据类型设置用户名/密码- 这是错误的。查看有关使用证书客户端的消息安全性的文章

于 2012-08-13T23:25:21.263 回答