- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
C# application using vSphere SDK 5.5 fails to retrieve VM's data from VMware ESXi 4
Hi,
I am using vSphere 5.5 SDK to retrieve hosts and vm's data from VMware ESXi 4. The application successfully fetches data for hosts but it fails with the below exception when I try to retrieve data for datastores or vm's
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at Vim25Api.VimService.RetrieveServiceContent(ManagedObjectReference _this)
It fails (at highlighted red line) when I try to use below get properties method. Any help to resolve this would be greatly appreciated.
public static Object[] getProperties(ManagedObjectReference moRef, String[] properties) {
// PropertySpec specifies what properties to retrieve and from type of Managed Object
PropertySpec pSpec = new PropertySpec();
pSpec.type = moRef.type;
pSpec.pathSet = properties;
// ObjectSpec specifies the starting object and any TraversalSpecs used to specify other objects for consideration
ObjectSpec oSpec = new ObjectSpec();
oSpec.obj = moRef;
// PropertyFilterSpec is used to hold the ObjectSpec and PropertySpec for the call
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.propSet = new PropertySpec[] { pSpec };
pfSpec.objectSet = new ObjectSpec[] { oSpec };
// retrieveProperties() return the properties selected from PropertyFilterSpec
ManagedObjectReference _svcRef1 = new ManagedObjectReference();
_svcRef1.type = "Service Instance";
_svcRef1.Value = "Service Instance";
ServiceContent sic1 = null;
vim_svc.Timeout = 600000; //The value can be set to some higher value also.
sic1 = vim_svc.RetrieveServiceContent(_svcRef1);
ObjectContent[] ocs = new ObjectContent[20];
ocs = vim_svc.RetrieveProperties(sic1.propertyCollector, new PropertyFilterSpec[] { pfSpec });
// Return value, one object for each property specified
Object[] ret = new Object[properties.Length];
if (ocs != null) {
for (int i = 0; i < ocs.Length; i++) {
ObjectContent oc = ocs[i];
DynamicProperty[] dps = oc.propSet;
if (dps != null) {
for (int j = 0; j < dps.Length; ++j) {
DynamicProperty dp = dps[j];
//Find property path index
for (int p = 0; p < ret.Length; ++p) {
if (properties[p].Equals(dp.name)) {
ret[p] = dp.val;
}
}
}
}
}
}
return ret;
}