Imports System Imports System.Web.Services.Protocols Imports VimService Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sc As New SimpleClient() sc.CreateServiceRef("ServiceInstance") sc.Connect("Eric Sloof", "Adminuser", "Password") sc.Disconnect() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class Public Class SimpleClient Protected _service As VimService Protected _sic As ServiceContent Protected _svcRef As ManagedObjectReference Protected _propCol As ManagedObjectReference Protected _rootFolder As ManagedObjectReference Public Sub CreateServiceRef(ByVal svcRefVal As String) System.Net.ServicePointManager.CertificatePolicy = New CertPolicy() _svcRef = New ManagedObjectReference() _svcRef.type = "ServiceInstance" _svcRef.Value = svcRefVal End Sub Public Sub Connect(ByVal url As String, ByVal username As String, ByVal password As String) If _service IsNot Nothing Then Disconnect() End If _service = New VimService() _service.Url = url _service.CookieContainer = New System.Net.CookieContainer() _sic = _service.RetrieveServiceContent(_svcRef) _propCol = _sic.propertyCollector _rootFolder = _sic.rootFolder MsgBox(_sic.about.build) MsgBox(_sic.about.name) MsgBox(_sic.about.osType) MsgBox(_sic.setting.Value) MsgBox(_sic.rootFolder.Value) If _sic.sessionManager IsNot Nothing Then _service.Login(_sic.sessionManager, username, password, Nothing) End If End Sub Public Sub Disconnect() If _service IsNot Nothing Then _service.Logout(_sic.sessionManager) _service.Dispose() _service = Nothing _sic = Nothing End If End Sub _ Public Shared Sub Main(ByVal args As String()) If args Is Nothing OrElse args.Length < 2 Then MsgBox("Usage : SimpleClient ") End If Dim now1 As DateTime = DateTime.Now Dim sc As New SimpleClient() Try sc.CreateServiceRef("ServiceInstance") sc.Connect(args(0), args(1), args(2)) sc.Disconnect() Dim now2 As DateTime = DateTime.Now MsgBox("Start Time : " + now1.ToLongDateString() + " " + now1.ToLongTimeString()) MsgBox("End Time : " + now2.ToLongDateString() + " " + now2.ToLongTimeString()) Console.Out.WriteLine("Done") Catch se As SoapException MsgBox("Caught SoapException - " + " Actor : " + se.Actor.ToString() + " Code : " + se.Code.ToString() + " Detail XML : " + se.Detail.OuterXml) Catch e As Exception MsgBox("Caught Exception : " + " Name : " + e.[GetType]().Name + " Message : " + e.Message + " Trace : " + e.StackTrace.ToString()) End Try End Sub End Class Public Class CertPolicy Implements Net.ICertificatePolicy Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult Return True End Function End Class