我试图让我的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
如何修复第一个错误?我做错了什么?
由于
答案 0 :(得分:1)
在您的代码中,我不知道您将ClientCredentials实例添加为工厂端点上的行为的位置。
创建ClientCredentials实例并设置其属性后......执行此操作,
cfClient.Endpoint.Behaviors.Add(cc);
在致电之前,cfClient.CreateChannel();