C# 证书。 localMachine 与 CurrentUser
c# certificates. localMachine vs CurrentUser
我正在尝试让我的 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, i get the following error":
未提供客户端证书。在 ClientCredentials 中指定客户端证书。
当我使用 "currentUser" 时出现以下错误:
无法使用以下搜索条件找到 X.509 证书:StoreName 'TrustedPeople'、StoreLocation 'CurrentUser'、FindType 'FindByThumbprint'、FindValue
我该如何解决第一个错误?我做错了什么?
谢谢
在您的代码中,我没有看到您在哪里将 ClientCredentials 实例添加为工厂端点上的行为。
创建 ClientCredentials 实例并设置其属性后...执行此操作,
cfClient.Endpoint.Behaviors.Add(cc);
调用前,cfClient.CreateChannel();
我正在尝试让我的 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, i get the following error":
未提供客户端证书。在 ClientCredentials 中指定客户端证书。
当我使用 "currentUser" 时出现以下错误:
无法使用以下搜索条件找到 X.509 证书:StoreName 'TrustedPeople'、StoreLocation 'CurrentUser'、FindType 'FindByThumbprint'、FindValue
我该如何解决第一个错误?我做错了什么?
谢谢
在您的代码中,我没有看到您在哪里将 ClientCredentials 实例添加为工厂端点上的行为。
创建 ClientCredentials 实例并设置其属性后...执行此操作,
cfClient.Endpoint.Behaviors.Add(cc);
调用前,cfClient.CreateChannel();