Hi All,
I am hosting a C# webservice in IIS that makes calls against our vsphere instance to perform certain functions. One basic call is to get a list of all VMs. Every so often, the webservice will get in some state in which the call returns null (we always have many VMs up):
List<EntityViewBase> views = c.FindEntityViews(typeof(VirtualMachine), null, null, null); if (views== null) throw new Exception("List of VMs from VimClient.FindEntityViews is null!");
At this point, I believe that this occurs if the webservice has not been restarted or recycled in some time. Most likely, I am storing the VimClient incorrectly.
I am caching the VimClient connection in the following way. My reason for doing so is to save time on calls (it takes roughly 20 seconds to call VimClient.Connect() upon each webservice call if I don't do this).
1) Upon webservice startup, I call
private static VimClient _vsphereClientConnection = null; _vsphereClientConnection = new VimClient(); ServiceContent sc = _vsphereClientConnection.Connect(vsphereServerURL); UserSession us = _vsphereClientConnection.Login(vsphereUsername, vspherePassword);
2) I then grab this instance of VimClient whenever I need to perform a function against the vSphere instance
public static VimClient VSphereClientConnection { get { Initialize.waitForInitialization(0); return _vsphereClientConnection; } }
where Initialize.waitForInitialization() checks whether VimClient has finished connecting to vSphere.
Am I caching this connection improperly? Is there a better way to do this/a way to do it at all? Or perhaps I am making a wrong assumption about why FindEntityViews is returning null.
I was thinking that in the property VSphereClientConnection, I could detect whether the connection has timed out in some way and re-connect it, but that is not ideal because then the user would have to wait for initialization again. I'm also not sure how to check whether the service is in a bad state without making a call that I know does not work in these 'bad' states.
Thanks,
Jason