WCF distributed development common error (24): cocould not establish trust relationship for the SSL/TLS Secure Channel with authorit

Source: Internet
Author: User

Use TransmissionSecurityMode. Certificates are used to establish SSL and host port certificates.ConfigurationAn error occurred while calling the service.
[1] error message:
Cocould not establish trust relationship for the SSL/TLS Secure Channel with authority 'computer: 100 '.
You cannot establish a trust relationship with an authorized computer as an SSL/TLS security channel.
Connection to the WCF Chinese Forum: cannot establish a trust relationship with the authorized computer for the SSL/TLS Security Channel: cocould not establish trust relationship for the SSL/TLS Secure Channel with authority 'computer: 8080'
Error:

Wcfsecuritynegotiationexception.gif (13.65 K)

8/11/2009 10:44:51

[2] configuration information:
2.1 Server Configuration:
The server sets a certificate and does not adopt Client Security Authentication. The security mode is transmission security. The server configuration information is as follows:

  1. <Services>
  2. <Service behaviorconfiguration = "wcfservice. wcfservicebehavior" name = "wcfservice. wcfservice">
  3. <Endpoint
  4. Address = "wcfservice"
  5. Binding = "wshttpbinding"
  6. Bindingconfiguration = "basicwithtransport"
  7. Contract = "wcfservice. iwcfservice">
  8. </Endpoint>
  9. <Endpoint address = "mex" binding = "mexhttpsbinding" Contract = "imetadataexchange"/>
  10. <Host>
  11. <Baseaddresses>
  12. <Add baseaddress = "https: // machine: 9001/"/>
  13. </Baseaddresses>
  14. </Host>
  15. </Service>
  16. </Services>
  17. <Behaviors>
  18. <Servicebehaviors>
  19. <Behavior name = "wcfservice. wcfservicebehavior">
  20. <Servicemetadata httpsgetenabled = "true"/>
  21. <Servicedebug includeexceptiondetailinfaults = "false"/>
  22. <Servicecredentials>
  23. <Servicecertificate storename = "my" x509findtype = "findbysubjectname" findvalue = "wcfhttps" storelocation = "localmachine"/>
  24. </Servicecredentials>
  25. </Behavior>
  26. </Servicebehaviors>
  27. </Behaviors>
  28. <Bindings>
  29. <Wshttpbinding>
  30. <Binding name = "basicwithtransport">
  31. <Security mode = "transport">
  32. <Transport clientcredentialtype = "NONE"/>
  33. </Security>
  34. </Binding>
  35. </Wshttpbinding>
  36. </Bindings>

CopyCode

2.2 client Configuration:
After the client adds a service reference, it calls the WCF Service directly by instantiating the class, and the result shows that the trust relationship cannot be established for SSL.

    1. Wcfclient. clientproxy. wcfserviceclient wcfserviceproxyhttp = new wcfclient. clientproxy. wcfserviceclient ("wshttpbinding_iwcfservice ");
    2. // Call the sayhello service by proxy
    3. String sname = "Frank Xu Lei wshttpbinding ";
    4. String sresult = string. empty;
    5. Sresult = wcfserviceproxyhttp. sayhello (sname );

Copy code

[3] Problem Analysis:
Cocould not establish trust relationship for the SSL/TLS Secure Channel with authority 'computer: 100 '.
You cannot establish a trust relationship with an authorized computer as an SSL/TLS security channel.
The actual cause has a lot to do with the certificate. Here, the certificate is a certificate trusted by the certificate authority. This certificate cannot be trusted when a secure session is established between the client and the server.
Another possible cause is that you use this certificate in other domains, which may also lead to errors.
[4] solution:
3.1: Define a class to verify and process remote X.509 certificates. The return value is true. we need to define a class by ourselves, and then execute it once before the customer monotonous use of the WCF Service. The Code is as follows:

  1. Public static class util
  2. {
  3. /// <Summary>
  4. /// Sets the CERT policy.
  5. /// </Summary>
  6. Public static void setcertificatepolicy ()
  7. {
  8. Servicepointmanager. servercertificatevalidationcallback
  9. + = Remotecertificatevalidate;
  10. }
  11. /// <Summary>
  12. /// Remotes the certificate validate.
  13. /// </Summary>
  14. Private Static bool remotecertificatevalidate (
  15. Object sender, x509certificate cert,
  16. X509chain chain, sslpolicyerrors error)
  17. {
  18. // Trust any certificate !!!
  19. System. Console. writeline ("Warning, trust any certificate ");
  20. Return true;
  21. }
  22. }

Copy code

you must call this method before calling the operation: util. setcertificatepolicy (); sresult = wcfserviceproxyhttp. sayhello (sname);
3.2: You must install with the Certificate Authority on the client and server. Then create a trusted root certificate authority certificate. Can refer to this:
http://www.codeplex.com/WCFSecur... ringtitle = How % 20tos
[5] summary:
the second mechanism used when developing and deploying the WCF Service for Windows Server products. The certificate issued by the certificate authority. The first method of learning is normal. WCF secure development programming practices are a complex process. In addition to basic security knowledge, you must be proficient in using various certificates for production, installation, and SSL certificates. configuration and other tools . In Windows server2003, The vitsa system is quite different. In general XP system development and learning, a write service needs to be installed, and the debugging process is also cumbersome. Once a bit of configuration is incorrect, an exception occurs. Learn with patience.
references: 1. cocould not establish trust relationship for the SSL/TLS Secure Channel with authority pC1 2.wcf cocould not establish trust relationship for the SSL/sectls ure channel with authority

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.