It is difficult to manually or programmatically call the https WCF Service signed by X.509 certificate

Source: Internet
Author: User

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 );

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.