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

Page 873

Advertising
background image

Brocade Virtual ADX XML API Programmer’s Guide

863

53-1003248-01

Example: Unbinding a real server from a VIP

B

// 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.

//

// Parameters: addr - the ip address which needs to be validated.

//

// Return Value: Success if true.

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

public bool IsValidIP(string addr)

{

System.Net.IPAddress ipAddress = null;

bool isValidIp = System.Net.IPAddress.TryParse(addr, out ipAddress);

return isValidIp;

}

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

Advertising