比较难 如何手工 或编程实现 调用 X.509 certificate 签名的 https WCF Service
当你在visual studio里 用 add service reference 调用一个只需X.509 certificate 签名 https WCF Service ,visual studio 自动生成一些代码和app.config或者web.config xml代码,基于这些自动生成的东东,很容易调用,但是部署时比较麻烦,得拷贝那些xml代码。
我搞了很长时间,终于搞懂了手工实现或者 programmatically implement,也就是无需机器生成的config xml代码
主要是给ChannelFactory添加X.509 certificate
service url 是 https://service.uhone.com/QuoteTransfer/QuoteTransfer.svc
[csharp]
BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();
binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.TransportWithMessageCredential;
binding.Security.Message.ClientCredentialType = System.ServiceModel.BasicHttpMessageCredentialType.Certificate;
EndpointAddress endpoint = new EndpointAddress(url);
ChannelFactory<QuoteTransferContract> factory = new ChannelFactory<QuoteTransferContract>(binding, endpoint);
factory.Credentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectDistinguishedName, "CN=****");
QuoteTransferContract proxy = factory.CreateChannel();
return proxy.SaveQuoteTransfer(request);
补充:软件开发 , C# ,