Connect to the Cobra Web Service Host

Connect to the Web service host in order to use the Cobra Web services and create applications that can execute Cobra functionalities over the network.

The first step in using the ClientAPI is to create an instance of the CobraServices class. This is a root class that consumes the Cobra Web service host. You can construct this class the same way you normally create an object from a class by using the new keyword. For example:

CobraServices cobraServices = new CobraServices();

Authenticate Cobra

Cobra Web service supports native and Windows authentication.

Provide Cobra Username and Password

If Cobra is configured to use native authentication, you need to define the Cobra user on the instance of the CobraServices class. The user can be specified in the ServiceIdentityData property. For example:

cobraServices.ServiceIdentityData.Username = "SYSADMIN";

cobraServices.ServiceIdentityData.Password = "password";

Authenticate Windows

If Cobra is configured to use Windows Authentication, you do not need to supply the Cobra username and password to the ServiceIdentityData property on the instance of CobraServices class. The Cobra Web Service ClientAPI automatically transfers your Windows credentials to the Cobra Web service host. The Cobra Web service host uses the Windows credentials as the Cobra user.

Call the Login Operation to Connect to the Cobra Web Service Host

Since the CobraServices class is responsible in consuming the Cobra Web service host, the instance of the class should be connected to the Web service before you could perform some Cobra actions like running Advance Calendar, Calculate Progress, or Calculate Forecast. To connect to the Web service, you must invoke the Login method. For example:

LoginResult loginResult = cobraServices.Login();

This will always be true in the current version of Cobra Web service. The LoginResult class also contains a String property named ErrorMessage, which currently is always empty.

The Login method returns an instance of LoginResult class that contains a Boolean property named Success. The Success property determines if the Login method succeeds. In the current version of the Cobra Web service, this will always be true. In the future version, the value of this property will identify whether the Cobra user is valid or not. The LoginResult class also contains a String property named ErrorMessage, which in the future versions will contain the error message why the validation failed.

To be compatible in the future version, it is recommended to check for the value of these properties before doing any Cobra actions. For example:

if (loginResult.Success) {

// Run processes here.

}

else {

MessageBox.Show(loginResult.ErrorMessage, "Login Failed", MessageBoxButtons.Ok, MessageBoxIcons.Error);

}