Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.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
.net net WCF客户端配置htts_.net_Web Services_Wcf_Webservice Client - Fatal编程技术网

.net net WCF客户端配置htts

.net net WCF客户端配置htts,.net,web-services,wcf,webservice-client,.net,Web Services,Wcf,Webservice Client,我正在尝试连接到web服务的https://trackingqa.estafeta.com/Service.asmx'编程上,我的意思是没有配置的代码(.config) 我试试这个 BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport); binding.Security.Transport.ClientCredentialType = HttpClientCredentia

我正在尝试连接到web服务的https://trackingqa.estafeta.com/Service.asmx'编程上,我的意思是没有配置的代码(.config) 我试试这个

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
        EndpointAddress endpoint = new EndpointAddress(url);
        ServiceSoapClient client = new ServiceSoapClient(binding, endpoint);
但我得到了这个错误:

未提供客户端证书。在ClientCredentials中指定客户端证书

我在MSDN()上找到了此文档

我试着这样做:

client.ClientCredentials.ClientCertificate.SetCertificate(
            System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser,
            System.Security.Cryptography.X509Certificates.StoreName.My,
            System.Security.Cryptography.X509Certificates.X509FindType.FindBySubjectName, "TrackingQA.estafeta.com");
但是我得到了这个错误:

异常:找不到具有以下搜索条件的X.509证书:StoreName“My”、StoreLocation“CurrentUser”、FindType“FindBySubjectName”、FindValue“TrackingQA.estafeta.com”

我的问题是如何在客户端配置de endpoint

我找到了一个解决方案。, 对我有用

  • 设置安全协议

     ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    
  • 设置证书

     client.ClientCredentials.ClientCertificate.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(Convert.FromBase64String(StringCertificateBase64));
    
  • 完整代码:

    var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
            EndpointAddress endpoint = new EndpointAddress(url);
            ServiceSoapClient client= new ServiceSoapClient(binding, endpoint);
            client.ClientCredentials.ClientCertificate.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(Convert.FromBase64String(StringCertificateBase64));