Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调用带有证书的第三方web服务时,无法为具有权限的SSL/TLS建立安全通道_C#_Asp.net - Fatal编程技术网

C# 调用带有证书的第三方web服务时,无法为具有权限的SSL/TLS建立安全通道

C# 调用带有证书的第三方web服务时,无法为具有权限的SSL/TLS建立安全通道,c#,asp.net,C#,Asp.net,我的项目使用了visual studio 2010,是一个带有c#的web应用程序项目。我为web服务添加了web引用 当我尝试使用UAT服务器中的证书访问第三方web服务时,无法为具有权限的SSL/TLS建立安全通道。证书已过期。我已经为本地计算机和当前用户添加了信任根证书和个人证书。当我使用web服务应用程序而不是web应用程序调用时,它会工作 下面是我在调用web服务时用来添加证书并绕过证书错误的代码 AServiceReference.AServiceClient client = ne

我的项目使用了visual studio 2010,是一个带有c#的web应用程序项目。我为web服务添加了web引用

当我尝试使用UAT服务器中的证书访问第三方web服务时,无法为具有权限的SSL/TLS建立安全通道。证书已过期。我已经为本地计算机和当前用户添加了信任根证书和个人证书。当我使用web服务应用程序而不是web应用程序调用时,它会工作

下面是我在调用web服务时用来添加证书并绕过证书错误的代码

AServiceReference.AServiceClient client = new AServiceReference.AServiceClient();

X509Certificate2 cert = new X509Certificate2("CERTIFICATE","PASSWORD");
client.ClientCredentials.ClientCertificate.Certificate = cert;

System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

将此添加到web.config文件中,您可能会很好:

<bindings>
  <basicHttpBinding>
    <binding name="xxxBinding">
      <security mode="Transport">
        <transport clientCredentialType="Certificate"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

当我负责附加客户证书时,我可以通过以下两种方式之一来完成。看起来你并没有将客户端证书(如果你正在使用的话)附加到任何地方

1:像你一直在做的那样通过代码

proxyClient.ClientCredentials.ClientCertificate.SetCertificate(
     StoreLocation.CurrentUser,
     StoreName.My,
     X509FindType.FindByThumbprint,
     "6D0DBF387484B25A16D0E3E53DBB178A366DA954");
2:通过web/app.config文件中的配置

<behaviors>
  <endpointBehaviors>
    <behavior name="ohBehave">
      <clientCredentials useIdentityConfiguration="false">
        <clientCertificate findValue="c6dafea24197cd6a6f13e846ffcdf70220d23ec2" storeLocation="CurrentUser"
          x509FindType="FindByThumbprint" />            
      </clientCredentials>          
    </behavior>
  </endpointBehaviors>
</behaviors>

<client>
  <endpoint address="https://myservice.ca/SubmitService/Submit.svc"
    behaviorConfiguration="ohBehave" binding="customBinding" bindingConfiguration="SubmitBinding"
    contract="SubmitService.Submit" name="SubmitDev" />
</client>

只要证书在指定的存储中,它就应该被附加

我还必须在.config文件中使用customBinding,因为我们也想传递凭据(注意客户端证书的httpsTransport节点):



仍然无法为具有权限的SSL/TLS建立安全通道=(我设法在我的生产服务器上获得了响应成功,但在UAT服务器上没有。你知道吗?@belltric你也在UAT上使用https?或http?生产和UAT都连接到https web服务。UAT证书已过期。System.Net.ServicePointManager.ServerCertificateValidationCallback=委托{return true;};这将绕过过期证书,对吗?看起来不起作用。你有什么想法吗?也许可以看看Marc Gravell在这个问题上的清单:@Rafa已经遵循了这些步骤,但仍然失败在这种情况下,我很抱歉我帮不上忙,通常它应该起作用,也许如果你告诉我们错误,你确定你没有CORS问题吗那是什么?
    <binding name="SubmitBinding">
      <security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport"
        requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
        <localClientSettings detectReplays="false" />
        <localServiceSettings detectReplays="false" />
      </security>
      <textMessageEncoding messageVersion="Soap11">
        <readerQuotas maxDepth="32" maxStringContentLength="200000000"
          maxArrayLength="200000000" maxBytesPerRead="200000000" />
      </textMessageEncoding>
      <httpsTransport maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
        maxBufferSize="200000000" requireClientCertificate="true" />
    </binding>