How do I create a user account via the Web Services?

0 Likes

Problem:

How do I create a user account via the Web Services?

Resolution:

The following code samples will be provided in the Java programming language.

Firstly we must login and obtain a session id which will allow us to interact with SilkCentral via the Web Services. This is achieved by calling the logonUser method of the sccsystem service, as shown in the below snippet:

//Connect to the sccsystem web service
SccsystemSoapBindingStub binding;
try {

binding = (SccsystemSoapBindingStub)
new SystemServiceServiceLocator().getsccsystem();

}
catch (Exception e) {

e.printStackTrace();

}

//logon to a SilkCentral session us
long sessionID = -3;
try{

sessionID = binding.logonUser("admin", "admin");
System.out.println(value);

}
catch(Exception e){

e.printStackTrace();

}

Now that we have successfully obtained a session id we can now move on with creating a user account via the Web Services. The steps involved in this process will require us to connect to the sccentities service, that contains the createUser method, which will subsequently allow us to create our user account via the web services. To connect to the sccentities Web Service see the following snippet:

//Connect to the sccentities web service
SccentitiesSoapBindingStub entBind;
try{

entBind = (SccentitiesSoapBindingStub) new MainEntitiesServiceLocator().getsccentities();

}
catch(Exception e){

e.printStackTrace();

}


Now that we can use the sccentities Web Service, we can now proceed with creating our user account. To perform this action via the Web Services we must make use of the UserDetails class, an instance of which will hold all the required details for our user account. See the following code snippet for the creation of a UserDetails instance and its creation via the Web Services:

//try to create the user
UserDetails newUser;
int iArray = {0}

try{
//Setup the User Details

newUser = new UserDetails();
newUser.setRoleId(5);
newUser.setAssignedProjects(iArray);
newUser.setEMail("test@borland.com");
newUser.setTimeZoneId("Europe/Belfast");
newUser.setDateFormat("EEE, MMM dd, yyyy - h:mm:ss a");
newUser.setShortDateFormat("M/d/yyyy, h:mm a");
newUser.setFirstDayOfWeek(2);
newUser.setPageRefreshTime(10);
newUser.setSeparatorString(",");
newUser.setLogin("Web_Service_User");
newUser.setFirstName("Some_Name");
newUser.setIsLocked(false);

//create the User
int i = entBind.createUser(sessionID, newUser);

}
catch(Exception e){

e.printStackTrace();

}


When the above snippet is executed, the corresponding user account will be created within SilkCentral Test Manager.


Old KB# 25166
Comment List
Anonymous
Related Discussions
Recommended