SetCertificate Method

Applies to TestComplete 12.60, last modified on September 17, 2018

Description

Use this method to define the certificate used to represent the web service under test by specifying the subject distinguished name.

Declaration

ClientCertificateObj.SetCertificate(SubjectNameStoreLocationStoreName)

ClientCertificateObj An expression, variable or parameter that specifies a reference to a ClientCertificate object
SubjectName [in]    Required    String    
StoreLocation [in]    Required    Integer    
StoreName [in]    Required    Integer    
Result None

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

SubjectName

Specifies the subject distinguished name.

StoreLocation

Specifies the location of the X.509 certificate store. The allowed parameter values are:

Constant Value Description
slCurrentUser 0 Specifies the X.509 certificate store used by the current user.
slLocalMachine 1 Specifies the X.509 certificate store assigned to the local machine.

StoreName

Specifies the name of the X.509 certificate store to open. The allowed parameter values are:

Constant Value Description
snAddressBook 1 Specifies the X.509 certificate store for other users.
snAuthRoot 2 Specifies the X.509 certificate store for third-party certificate authorities (CAs).
snCertificateAuthority 3 Specifies the X.509 certificate store for intermediate certificate authorities (CAs).
snDisallowed 4 Specifies the X.509 certificate store for revoked certificates.
snMy 5 Specifies the X.509 certificate store for personal certificates.
snRoot 6 Specifies the X.509 certificate store for trusted root certificate authorities (CAs).
snTrustedPeople 7 Specifies the X.509 certificate store for directly trusted people and resources.
snTrustedPublisher 8 Specifies the X.509 certificate store for directly trusted publishers.

Result Value

None.

Example

The code snippet below demonstrates how you can use the SetCertificate method to define the certificate.

JavaScript, JScript

function ServiceSertificate()
{
  var MyWebService, Crd, Certificate;
  
  // Obtain the tested web service
  MyWebService = WebServices.SampleWebService;
  
  // Call a web service Credentials property
  Crd = MyWebService.Credentials;
  
  // Obtain the client certificate object
  Certificate = Crd.ClientCertificate;
  
  // Defines the client certificate
  Certificate.SetCertificate(slLocalMachine, snMy, "CN = sample_subject_name.com");
}

Python

def ServiceCertificate():
  # Obtain the tested web service
  MyWebService = WebServices.SampleWebService
  # Call a web service Credentials property 
  Crd = MyWebService.Credentials
  # Obtain the client certificate object
  Certificate = Crd.ClientCertificate
  # Defines the client certificate
  Certificate.SetCertificate(slLocalMachine, snMy, "CN = sample_subject_name.com")

VBScript

Sub ServiceSertificate

  Dim MyWebService, Crd, Certificate
  
  ' Obtain the tested web service
  Set MyWebService = WebServices.SampleWebService
  
  ' Call a web service Credentials property
  Set Crd = MyWebService.Credentials
  
  ' Obtain the client certificate object
  Set Certificate = Crd.ClientCertificate
  
  ' Defines the client certificate
  Call Certificate.SetCertificate(slLocalMachine, snMy, "CN = sample_subject_name.com")

End Sub

DelphiScript

function ServiceSertificate();
var MyWebService, Crd, Certificate: OleVariant;
begin
  
  // Obtain the tested web service
  MyWebService := WebServices.SampleWebService;
  
  // Call a web service Credentials property
  Crd := MyWebService.Credentials;
  
  // Obtain the client certificate object
  Certificate := Crd.ClientCertificate;
  
  // Defines the client certificate
  Certificate.SetCertificate(slLocalMachine, snMy, 'CN = sample_subject_name.com');

end;

C++Script, C#Script

function ServiceSertificate()
{
  var MyWebService, Crd, Certificate;
  
  // Obtain the tested web service
  MyWebService = WebServices["SampleWebService"];
  
  // Call a web service Credentials property
  Crd = MyWebService["Credentials"];
  
  // Obtain the client certificate object
  Certificate = Crd["ClientCertificate"];
  
  // Defines the client certificate
  Certificate["SetCertificateEx"]( slLocalMachine, snMy, "CN = sample_subject_name.com" );
}

See Also

ClientCertificate Object
Testing Web Services

Highlight search results