Brocade Virtual ADX XML API Programmer’s Guide (Supporting ADX v03.1.00) User Manual

Page 848

Advertising
background image

838

Brocade Virtual ADX XML API Programmer’s Guide

53-1003248-01

Example - Provisioning real and virtual servers

B

if (m_SYSService == null)

m_SYSService = new SysService();

return m_SYSService;

}

/////////////////////////////////////////////////////////////////////////////

// Name: OpenConnection

//

// Description: This function forms the URL based on the given DeviceName

// and sets the required parameters to the WSDL SLB Service object

// inorder to communicate witht the ADX Box.

//

// Parameters: DeviceName - The IP Adress of the ADX Box

// UserName - The user name associated with the ADX Box

// Password - The password associated with the ADX Box

//

/////////////////////////////////////////////////////////////////////////////

public void OpenConnection(ref string DeviceName, ref string UserName, ref

string Password)

{

//Check the given device name is valid

if (IsValidIP(DeviceName) == false)

{

throw new Exception("Invalid IP/Device Name. Please enter a valid

Device Name.");

}

//Get the WSDL SLB Object

SlbService objSlbService = null;

objSlbService = GetSLBObject();

//Get the WSDL SYS Object

SysService objSysService = null;

objSysService = GetSYSObject();

string sSLBURL = "";

string sSYSURL = "";

string sUsernamePassword = "";

//For the service url with the given device name

sSLBURL = String.Format("http://{0}/WS/SLB", DeviceName);

sSYSURL = String.Format("http://{0}/WS/SYS", DeviceName);

objSlbService.Url = sSLBURL;

objSysService.Url = sSYSURL;

sUsernamePassword = UserName + ":" + Password;

////Sets the header information with header name as Authorization and

header value as Basic + encrypted username:password combination

objSlbService.SetRequestHeader("Authorization", "Basic " +

Convert.ToBase64String(new

ASCIIEncoding().GetBytes(sUsernamePassword)));

objSysService.SetRequestHeader("Authorization", "Basic " +

Convert.ToBase64String(new

ASCIIEncoding().GetBytes(sUsernamePassword)));

objSlbService.PreAuthenticate = true;

objSysService.PreAuthenticate = true;

}

/////////////////////////////////////////////////////////////////////////////

// Name: IsValidIP

//

// Description: This function is being used to validate an IP address for

IPv4

// and IPv6 addresses.

Advertising