Creating a Proteus API Module for .NET and Powershell (Courtesy BlueCat Networks)



Prerequisites:
You will need the following tools installed to continue:
1. Web Services Description Language Tool (Wsdl.exe) from Microsoft. WSDL.exe is included in the .NET 2.0 SDK. (be sure to select your target .NET framework version) 

1. Creating a Proteus .NET proxy class and library.
To create the proxy class:
1. Run WSDL.exe from the .NET SDK to generate the proxy class source code file: 

wsdl.exe http://[ProteusIPOrHostName]/Services/API?wsdl /out:ProteusAPI.cs

To compile the proxy class to a library for use with PowerShell or .NET Projects.
1. Open the ProteusAPI.cs file in a text editor and locate the ProteusAPI() method. Modify the method definition to appear exactly as shown below and then save the file. 

public ProteusAPI()
this.CookieContainer = new System.Net.CookieContainer();
}
2. Compile the C# class to a DLL using the command line compiler or Visual Studio. 
If the compiler is not available in your system’s path environment variable it can be found here: 

C:\Windows\Microsoft.NET\Framework[64]\[.NETVersionNumber]\csc.exe. 

Command line compiler syntax is as follows: 

csc /t:library /out:ProteusAPI.dll ProteusAPI.cs 

(substitute double-quoted full paths to the ProteusAPI.cs file and the output ProteusAPI.DLL file if the input file isn’t in the command line prompt’s current directory)

3. OPTIONAL: Install the library into your workstation’s Global Assembly Cache: http://msdn.microsoft.com/en-us/library/2bc0cxhc.aspx

2. Using the Proteus proxy library
NOTE: The BlueCat Proteus Perl and Java API modules are compiled modules with specific helper methods that are not present in the Proteus SOAP API. Because the Proteus .NET library is generated directly from the Web Services Description Language (WSDL) file, it does not contain the helper methods described in the Perl and Java examples within the ‘API Sessions’, ’Java API Examples’, and ’Perl API Examples’ sections of the Proteus API Guide. The API Object Methods, API Constants, and API Method Reference sections of the Proteus API Guide are the sections you want to focus on for using the .NET module.
  • The ProteusAPI.cs file can now be added as a utility class to any Visual Studio C# project.
  • The ProteusAPI.dll can be added as a Reference to any Visual Studio project.
  • The ProteusAPI.dll can be used from PowerShell scripts. (see example below)

3. Using the Proteus proxy library with Microsoft Powershell
Once the Proteus.dll module has been compiled it can be used directly within Microsoft PowerShell scripts with full access to the Proteus Web Services API. The API Object Methods, API Constants, and API Method Reference sections of the Proteus API Guide are the sections you want to focus on for .NET and PowerShell.

PowerShell Example:

/* Replace [APIUserID] below with your Proteus API account username */ 
$proteusAPI_ID = '[APIUserID]' 
/* Replace [APIUserPassword] below with your Proteus API account password */ 
$proteusAPI_PWD = '[APIUserPassword]' 
/* Replace [PathToProteusAPI.dll] below with the single quoted path to your ProteusAPI.dll module, e.g. 'C:\ProteusAPI.dll' */ 
$proteusdll = [System.Reflection.Assembly]::LoadFile([PathToProteusAPI.dll]) 
/* Instantiate a new ProteusAPI Object */ 
$p1 = New-Object ProteusAPI 
/* Set the new ProteusAPI Object’s ‘url’ property to your Proteus IP or hostname and path to the web service endpoint */ 
$p1.url = "http://[ProteusIPOrHostName]/Services/API" 
/* Call the login() method passing the API username and password as defined above or as strings, e.g. $p1.login('username', 'password ') */ 
$p1.login($proteusAPI_ID, $proteusAPI_PWD) 
/* Call the Proteus API method(s) you wish to use, such as the addMACAddress() example below. */ 
$newMACProteusObjectId = $p1.addMACAddress('1','00-00-00-11-11-11', '') 
/* Do any further processing … */ 
/* Make sure to call the logout() method to close the session when finished. */ 
$p1.logout()

Creating a Proteus API Module for .NET and Powershell (Courtesy BlueCat Networks) Creating a Proteus API Module for .NET and Powershell (Courtesy BlueCat Networks) Reviewed by Shawn Woodward on 7:51 AM Rating: 5

3 comments:

  1. Hi admin, i went through article. As we all know, .net is most popular programming language and it offer huge career prospects for talented professionals. It’s totally awesome, keep on updating your blog with such awesome information.
    Regards,
    DOT NET Training in Chennai|Best DOT NET Training institute in Chennai

    ReplyDelete
  2. have one thats fully built and we can just download?

    ReplyDelete

Powered by Blogger.