Previous Topic: Handling ErrorsNext Topic: Retrieving Attributes


Creating and Maintaining a Connection

To create a web service connection and to log into the DSM web service, initialize both a web service locator, and a binding to the web service using SOAP. You must know the URL of the web service. In a standard DSM installation, the URL is in the format, http://<machinename>/udsm_r11_webservice/mod_gsoap.dll on Windows and http://<machinename>/UDSM_R11_WebService on Linux.

For Post R12.5 release, use the following web service end point, in addition to the previous URL:

Windows

http://<machinename>/DSM_Webservice/mod_gsoap.dll

Linux

http://<machinename>/DSM_WebService

You must initialize the web service locator (a) and then get a connection to the web service API using the location URL of the web service (b).

Example 1: Setting up the required connection variables

//This is the session ID used in all web service calls
//It is set up when you log into the web service
private String sessionId = "";	
//These are the UDSM Web Service objects you need to make
//web service calls
//(a)
private DSMWebServiceAPIService wsAPIservice = null;
//(b)
public DSMWebServiceAPISoapBindingStub wsAPIconnector = null;
private String serviceLocation="";
private java.net.URL endpoint = new java.net.URL(serviceLocation);

Note: This example is generated using Apache Axis version 1.2 and JDK 1.5.

Example 2: Creating the Web Service Connection

//create the Service Locator object -- this is required.
wsAPIservice = new WebServiceAPIServiceLocator();
//if the service locator object was created then carry on
if (wsAPIservice != null)
{
	try
	{
		//try to create the binding object to bind to the web 
		//service using the URI of the web service location
	     	wsAPIconnector= (WebServiceAPISoapBindingStub)
		wsAPIservice.getWebServiceAPIService(endpoint);
	}
	catch(Exception e)
	{
	     	throw e;
	}
}
else
{
	sessionId = "";
	return WEB_SERVICE_COULD_NOT_BE_INITIALISED;
}

Remember that java web service methods can throw web service exceptions that should be identified and handled.

Once a connection has been made, it is important to log into the DSM web service as you would to the DSM explorer. The Login method should be called with the credentials of a valid DSM user.

Example 3: Logging in to the DSM Web Service

//now try to log in to the new web service connection
//using the credentials from a config object (not described here)
	try
	{
sessionId = wsAPIconnector.Login(    cfg.getUserName(),cfg.getPassword(),cfg.getManager() );
	}
	catch (Exception e)
	{
	     sessionId = "";
	     throw e;
	}
     	
	//if the session Id is blank it means no session could be established
	if(sessionId.equals(""))
	{
		return SESSION_COULD_NOT_BE_ESTABLISHED;
	}
	else
	{
		return RESULT_OK;
	}