If you are writing .NET code using the VMWare SDK, you already know that the ESX host its self has the set of web services installed on it that we use in order to interact with the VMWare system.
One thing you might not know, is that if you have Virtual Center installed in your environment, that device also has the ESX Web Services installed on it. Now, what is the difference? Well, in fact there are really no differences in the web services themselves, just what actions are available to each system using the web services.
For example, if you connect to Virtual Center WEb Services, you have he ability to create folders, where as, in the ESX host folders are not supported.
So, how do we know, what type of system we are connected to? Well, its actually pretty simple.
There are two ways we can accomplish this. The fist creating an instance of the ServiceContent. Once you have that, you can then check a property called “multiHostSupported”.
This property till tell you if the host you are connected to, supports multi hosts. And only Virtual Center support multi hosts.
The second approach is to get the AboutInfo collection of the service object, and check the property of “apiType”. If this returns VirtualCenter then you are in fact connected to a VC box.
Once you have this you can then perform logic to make different API calls based on the type of system your are connect to.
Here is some sample code
this._vmService = new VimService();
vmService.Url = @"https:///sdk";
_vmService.CookieContainer = new System.Net.CookieContainer();
System.Net.ServicePointManager.CertificatePolicy = new TrustAllCerts();
ManagedObjectReference _object = new ManagedObjectReference();
_object.type = "ServiceInstance";
_object.Value = "ServiceInstance";
this._vmServiceContent = this._vmService.RetrieveServiceContent(_object);
this._vmLoginSession = _vmService.Login(_vmServiceContent.sessionManager, "", "", null);
AboutInfo _apiAboutInfo = this._vmServiceContent.about;
if ( _apiAboutInfo.apiType.ToLower() == "virtualcenter" )
{
Console.WritLine(“Connected to a VC API”);
}</pre>
Hope this helps.