When you use add service reference in visual studio to call an https WCF Service with only X.509 certificate Signature, visual studio automatically generates code and apps. config or web. the config xml code is easy to call based on these automatically generated items, but it is difficult to deploy and you have to copy the xml code.
After a long time, I finally understood the manual implementation or programmatically implement, that is, the config xml code generated by the machine is not required.
Add X.509 certificate to ChannelFactory
Service url is 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 );