Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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#和用于SOAP的Visual Studio WSDL插件-我可以';t添加证书,或其添加方式错误_C#_Ssl_Soap_Wsdl - Fatal编程技术网

C#和用于SOAP的Visual Studio WSDL插件-我可以';t添加证书,或其添加方式错误

C#和用于SOAP的Visual Studio WSDL插件-我可以';t添加证书,或其添加方式错误,c#,ssl,soap,wsdl,C#,Ssl,Soap,Wsdl,我从一些wsdl和xsd文件中使用visualstudio插件生成了代码 由于保密协议的原因,我无法在这里发布这些文件,但我有如下方法: B2BGetAcctServicePortTypeClient cli = new B2BGetAcctServicePortTypeClient(); X509Certificate2 cert = new X509Certificate2("../../../Certs/pathTo.p12", "password", X509KeyStorageFl

我从一些
wsdl
xsd
文件中使用visualstudio插件生成了代码

由于保密协议的原因,我无法在这里发布这些文件,但我有如下方法:

B2BGetAcctServicePortTypeClient cli = new B2BGetAcctServicePortTypeClient();

X509Certificate2 cert = new X509Certificate2("../../../Certs/pathTo.p12", "password", X509KeyStorageFlags.DefaultKeySet);


// 1st:
cli.ClientCredentials.ClientCertificate.Certificate = cert;

//2nd:
cli.ChannelFactory.Credentials.ClientCertificate.Certificate = cert;

//3rd:
cli.ChannelFactory.Credentials.ServiceCertificate.DefaultCertificate = cert;

这3个变量允许我添加
X509Certificate2
,我尝试了每一个变量,但没有一个有效

我确信该证书是好的,因为当我以传统方式使用
System.Net
请求和客户端进行请求时,它看起来很好,我没有错误(我将在这个问题的末尾发布错误内容)。 我需要使用生成的类,因为我将发送大量数据。我不想犯人为错误,这是我客户的软件,不是我的,所以我真的需要使用VisualStudio插件来生成我的参考代码

因此,我尝试了第二种方法来添加此证书:

cli.ClientCredentials.ClientCertificate.Certificate.Import("../../../Certs/pathTo.p12", "password", X509KeyStorageFlags.DefaultKeySet);
X509KeyStorageFlags中的每个标志都可用,但它总是给我

NullReferenceException

我在第一个示例中遇到的错误:

System.AggregateException: One or more errors occurred. (Could not establish trust relationship for the SSL/TLS secure channel with authority 'ADDRESS'.) ---> System.ServiceModel.Security.SecurityNegotiationException: Could not establish trust relationship for the SSL/TLS secure channel with authority 'ADDRESS'. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: A security error occurred                                                                                                  
我已经用我的想法来解决这个问题了,而我的证书经验是中等偏下的,所以请给我一些建议

无论如何,我尝试从我的证书存储(本地和计算机)添加证书,结果相同


Ps证书在谷歌Chrome上进行了测试,我可以毫无问题地提出GET请求。安全连接已建立,因此我确实确信证书已更正

您不需要添加多个证书吗?
System.AggregateException: One or more errors occurred. (Could not establish trust relationship for the SSL/TLS secure channel with authority 'ADDRESS'.) ---> System.ServiceModel.Security.SecurityNegotiationException: Could not establish trust relationship for the SSL/TLS secure channel with authority 'ADDRESS'. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: A security error occurred