Unable to connect to ESX server

Oct 1, 2009 at 6:27 PM


I'm trying to connect to my ESX server using the following code:

VMWareVirtualHost virtualHost = new VMWareVirtualHost();

virtualHost.ConnectToVMWareVIServer("https://myservername/sdk", "root", "xxxx");

The code throws an exception stating that it is unable to connect to host.

I'm able to connect to the server, list snapshots, etc with the VMRun.exe tool included with the VIX framework using the servername and password that I'm passing into the ConnectToVMWareVIServer method, so I'm pretty sure it's not my server. Any ideas?

Oct 1, 2009 at 6:37 PM
Edited Oct 1, 2009 at 6:37 PM

Hi mcheshier,

I'm fairly new at this myself, so this may be entirely wrong, but is it that you're passing in a URI when that method needs a string that's just the servername.

For the full URI, try

virtualHost.ConnectToVMWareVIServer(new Uri(vimHost), userName, password, 100);

and, nabbing a bit of dblock's code which seems to confirm this theory, here's what the method you're called is doing:

public void ConnectToVMWareVIServer(string hostName, string username, string password, int timeoutInSeconds)
            ConnectToVMWareVIServer(new Uri(string.Format("https://{0}/sdk", hostName)),
                username, password, timeoutInSeconds);


thus ending up with https://https://myservername/sdk/sdk, of course.


Oct 1, 2009 at 7:42 PM

Yep, that worked. I just passed in myservername WITHOUT the https:// prefix and /sdk suffix.