List running Virtual Servers using C#

The following code uses ZXTM's Control API to list all the running virtual servers on a cluster. The code is written in C#.


listVS.cs

using System;
using System.Net;
using System.IO;
using System.Security.Cryptography.X509Certificates;

public class AllowSelfSignedCerts : IcertificatePolicy {
   public bool CheckValidationResult(
      ServicePoint sp, X509Certificate cert,
      WebRequest request, int problem )
   {
      return true;
   }
}

public class listVS {
   public static void Main( string [] args ) {

      System.Net.ServicePointManager.CertificatePolicy =
         new AllowSelfSignedCerts();

      string url= "https://host:9090/soap";
      string username = "username";
      string password = "password";

      try {
         ZXTM.VirtualServer p = new ZXTM.VirtualServer();
         p.Url = url;
         p.Credentials = new NetworkCredential( username, password );

         string[] names = p.getVirtualServerNames();
         bool[] enabled = p.getEnabled( names );

         for ( int i = 0; i < names.Length; i++ ) {
            if( enabled[i] ) {
               Console.WriteLine( "{0}", names[i] );
            }
         }
      } catch ( Exception e ) {
         Console.WriteLine( "{0}", e );
      }
   }
} 

Running the example

This code works with the .NET 1.1 SDK and with Mono (use the most recent Mono build available from http://www.mono-project.com/). Using .Net 1.1, compile and run this example as follows:

C:\> wsdl -o:VirtualServer.cs -n:ZXTM VirtualServer.wsdl
C:\> csc /out:listVS.exe VirtualServer.cs listVS.cs
C:\> listVS.exe
Main website
Mail servers
Test site

With Mono, compile and run as follows:

$ wsdl -o:VirtualServer.cs -n:ZXTM VirtualServer.wsdl
$ msc /out:listVS.exe /r:System.Web.Services VirtualServer.cs listVS.cs
$ ./listVS.exe
Main website
Mail servers
Test site

The WSDL interface specifications for the ZXTM Control API are located in ZEUSHOME/zxtm/etc/wsdl/.

Note the use of the IcertificatePolicy derived class to override the default certificate checking method. This allows the application to accept the ZXTM Admin Server's self-signed certificate.

Owen Garrett [Zeus Dev Team] 20 October 2005  Permalink  
Leave a comment ...
Your email address will not be displayed.
Your URL will be displayed.
This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
Download Free ZXTM Desktop Edition

Recent Articles

Other Resources



www.zeus.com