locked
Client certificate from within a services RRS feed

  • Question

  • Hi there,

    I have build a windows service wich will communicate to a web service.
    This web service requre a certificate for authorisation.

    When i run the services under "local system" it doesn't send the certificate to the web services.
    If i run the services under a user account it's perfectly, but this is not an option for us.

    How do make the services send the certificate to the web service when it is running under "local system"?

    Friday, December 22, 2006 10:31 AM

Answers

  • The solution was simple.
    The certificate has to be imported into the local machine store, before it can be used bij the services.

    Wednesday, December 27, 2006 10:55 AM

All replies

  • mrfatmen,

    I hope the following C# code will help you with the certificate to the web service:

    public void CallWebService()

      {

        // TODO: Replace with a valid path to your certificate

        string certPath = @"C:\WSClientCert.cer";

     

        // Instantiate the Web service proxy

        WebSvc.math mathservice = new WebSvc.math();

        mathservice.Url = @"https://wsserver/securemath/math.asmx";

     

        // create an X509Certificate object from the information

        // in the certificate export file and add it to the

        // ClientCertificates collection of the Web service proxy

        mathservice.ClientCertificates.Add(

            X509Certificate.CreateFromCertFile(certPath));

     

        long lngResult = 0;

        try

        {

          lngResult = mathservice.Add(Int32.Parse(operand1.Text),

              Int32.Parse(operand2.Text));

          string result = lngResult.ToString();

        }

        catch(Exception ex)

        {

          if(ex is WebException)

          {

            WebException we = ex as WebException;

            WebResponse webResponse = we.Response;

            throw new Exception("Exception calling method. " + ex.Message);

          }

        }

      }

     

    Tuesday, December 26, 2006 9:39 AM
  • Thx for the reply.

    This example works when running in an (console) application, but when i turn the application in a services.
    It will add the certificate to the proxyobject but it doesn;t send it to the web-service.

    It looks like the windows service (when run under local system) doesn't accept use a certificate.

    Tuesday, December 26, 2006 9:48 AM
  • Have you tried to add a reference of this program in your project?
    Tuesday, December 26, 2006 9:56 AM
  • Yes, it must be within the service system.
    When i set the application type (within my project, application) to windows application the code works.
    When i set it to windows service the code doesn't work.

    Without changing the code, so it isn't my code (i think).

    When i put the service under a user account it works, but i want it to run under local system.
    I import the certificate directly from the harddrive,no certificate store.

    Tuesday, December 26, 2006 2:30 PM
  • The solution was simple.
    The certificate has to be imported into the local machine store, before it can be used bij the services.

    Wednesday, December 27, 2006 10:55 AM
  • Hi all,

    I have the same problem with a Windows Service application targeting a Web Service based on WSE 2.0.I could install in the LocalMachine|Personal store the Client certificate, but needs also to import the public Server Certificate in the LocalMachine|OtherPeople store. How can I do that?

    Many thanks by advance

    Thursday, January 11, 2007 11:04 AM