Connect a Client to a Web Service with certificate RRS feed

  • Question

  • Hi

    I'm trying to connect to a Web Service which autenticate via certificate

    I have the certificate (.cer) and this is the code in C# , VS2010

    static void Main(string[] args)
                //// Get the certificate file address 
                string certPath = Properties.Settings.Default.RootCert;   
                 AdministrationService safa = new AdministrationService();
                 safa.Credentials = CredentialCache.DefaultCredentials;
                   AssignArtifactToCustomerParameters Ag = new AssignArtifactToCustomerParameters(); 
                    // Load the client certificate from a file.
                    X509Certificate x509 = X509Certificate.CreateFromCertFile(certPath);
                    //Add the certificate to the ClientCertificates collection of the Web service proxy.
                    Ag.ArtifactCode = "12345";
                    Ag.ArtifactTypeID = "5";
                    Ag.PlaceName = "IMPRES";
                    Ag.CustomerID = "12345678";
                    AssignArtifactToCustomerResult ar = safa.AssignArtifactToCustomer(Ag);
                catch (Exception e) 
                    Console.WriteLine ("Connection Error to Service<" + e.Message + ">" );

     I get the error "Could not establish a trust relationship for the SSL/TLS secure channel."

    Nevertheless, I installed the certificate via MMC and test the service call whith SOAPUI utility and I get a right answer from the WebService

    I tryed dozens of tips get from internet and spent a lot of hours but always fail


    Thanks for your answer



    Saludos David

    • Moved by Bob Shen Wednesday, March 20, 2013 4:24 AM
    Tuesday, March 19, 2013 1:51 PM


  • Hi,

    This error usually cased by an untrusted certificate, please check if you have placed the generated certificate in the "Trusted Root Certificate Authorities". And you may refer a kb below to check if it helps.

    #How to call a Web service by using a client certificate for authentication in an ASP.NET Web application

    Best Regards.

    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Haixia_XieModerator Tuesday, March 26, 2013 9:28 AM
    • Unmarked as answer by Dpozo Tuesday, March 26, 2013 9:33 AM
    • Marked as answer by Dpozo Tuesday, March 26, 2013 9:33 AM
    Wednesday, March 20, 2013 7:49 AM

All replies