Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.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# 如何在ASP.Net中使用证书调用soap API?_C#_Asp.net_Ssl_Soap - Fatal编程技术网

C# 如何在ASP.Net中使用证书调用soap API?

C# 如何在ASP.Net中使用证书调用soap API?,c#,asp.net,ssl,soap,C#,Asp.net,Ssl,Soap,我想使用soap API从系统中提取一些数据。API开发人员向我提供了两个证书,并要求我在代码中使用它们。他说,如果我在调用API时不使用它们,我将无法获得完整的数据集。这是我第一次想使用证书来调用soap API,我对此一无所知。我在网上做了一些搜索,但找不到任何对我有帮助的东西。 以下是我的申请详情: 1.ASP.net 2.C# 3.Net framework 4.0假设这是一个X509证书,您将生成对证书文件的引用,然后将其添加到WebRequest对象的ClientCertificat

我想使用soap API从系统中提取一些数据。API开发人员向我提供了两个证书,并要求我在代码中使用它们。他说,如果我在调用API时不使用它们,我将无法获得完整的数据集。这是我第一次想使用证书来调用soap API,我对此一无所知。我在网上做了一些搜索,但找不到任何对我有帮助的东西。 以下是我的申请详情: 1.ASP.net 2.C#
3.Net framework 4.0

假设这是一个X509证书,您将生成对证书文件的引用,然后将其添加到WebRequest对象的ClientCertificates属性中

//You must change the path to point to your .cer file location. 
X509Certificate Cert = X509Certificate.CreateFromCertFile("C:\\mycert.cer");
// Handle any certificate errors on the certificate from the server.
ServicePointManager.CertificatePolicy = new CertPolicy();
// You must change the URL to point to your Web server.
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://YourServer/sample.asp");
Request.ClientCertificates.Add(Cert);
Request.UserAgent = "Client Cert Sample";
Request.Method = "GET";
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
有关详细信息,请访问:

有时证书文件受密码保护。这是VB.Net代码,但当文件上有密码时,它会生成CERT对象:

Dim fs As FileStream = File.Open(certfilePath, FileMode.Open, FileAccess.Read)
Dim buffer As Byte()
ReDim buffer(fs.Length)
Dim count As Integer = fs.Read(buffer, 0, buffer.Length)
fs.Close()
Dim cert As X509Certificate2 = New X509Certificate2(buffer, passwordToFile)
还请注意,如果您使用的是SoapHttpClientProtocol(或将其继承到特定类中以使用此SOAP API,以及其他System.Web.Protocol元素),则它还包含ClientCertificates属性