【发布时间】:2015-04-19 00:31:37
【问题描述】:
我试图让我的 mvc3 应用程序通过 https 调用 Web 服务。这是我的代码:
var basicHttpsBinding = new BasicHttpsBinding();
basicHttpsBinding.MaxBufferPoolSize = 104857600;
basicHttpsBinding.MaxBufferSize = 104857600;
basicHttpsBinding.MaxReceivedMessageSize = 104857600;
basicHttpsBinding.Security.Mode = System.ServiceModel.BasicHttpsSecurityMode.Transport;
basicHttpsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
var endpointAddress = new EndpointAddress("web service url.asmx");
var cfClient = new ChannelFactory<ws_name_webreqSoap>(basicHttpsBinding, endpointAddress);
ClientCredentials cc = cfClient.Endpoint.Behaviors.Find<ClientCredentials>();
cc.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine,
StoreName.My,
X509FindType.FindByThumbprint,
"00000000000000000000000000000000000"
);
cfClient.CreateChannel();
var webServices = new ws_merit_webreqSoapClient(basicHttpsBinding, endpointAddress);
当我使用“LocalMachine,我得到以下错误”:
未提供客户端证书。在 ClientCredentials 中指定客户端证书。
当我使用“currentUser”时出现以下错误:
使用以下搜索条件找不到 X.509 证书:StoreName 'TrustedPeople'、StoreLocation 'CurrentUser'、FindType 'FindByThumbprint'、FindValue
如何解决第一个错误?我做错了什么?
谢谢
【问题讨论】:
-
您是将“00000000000000000000000000000000000”字符串传递给 SetCertificate 方法,还是只是从代码中删除了指纹字符串以便粘贴到此处?
-
我只是将其删除并粘贴到这里
-
是否在这一行抛出错误...'cfClient.CreateChannel();'?
标签: c# https certificate