I am trying to learn how to use the vSphere Web Services. My simple application is below. The project is made in C# with Visual Studio 2010. I am able to build the solution just fine. However, when I execute the following line of code, my CPU spikes up to about 50% for 2 minutes then completes the login process.
service = new Vim25Api.VimService();
Does anyone know why this might be happening? It makes the application extremely slow. I would think creating the VimService object would not be so CPU intensive.
Suggestions are welcome
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Net;
using Vim25Api;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
vcConnection.Login();
}
catch (Exception e)
{
Console.WriteLine(e.Source + " : " + "Error: " + e.Message);
Console.ReadLine();
}
}
}
public class svcConnection
{
private ManagedObjectReference svcRef;
private VimService service;
private ServiceContent sic;
private UserSession session;
private string strUrl;
private string strUser;
private string strPassword;
public svcConnection(string url, string user, string pwd)
{
try
{
strUrl = url;
strUser = user;
strPassword = pwd;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
svcRef = new ManagedObjectReference();
svcRef.type = "ServiceInstance";
svcRef.Value = "ServiceInstance";
service = new Vim25Api.VimService();
service.Url = url;
sic = service.RetrieveServiceContent(svcRef);
}
catch (Exception ex)
{
throw new Exception("Caught Exception: " + ex.Message);
}
}
public void Login()
{
try
{
session = service.Login(sic.sessionManager, strUser, strPassword, null);
}
catch (Exception ex)
{
throw new Exception("Caught Exception: " + ex.Message);
}
}
public static bool ValidateServerCertificate(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
}
}