Accessing the vSphere
Server from a Web Services Client
The steps that use the vSphere Web Services
API to create the connection are:
- Create a managed object reference for theServiceInstanceobject on the server.ManagedObjectReference SVC_INST_REF = new ManagedObjectReference(); SVC_INST_REF.setType("ServiceInstance"); SVC_INST_REF.setValue("ServiceInstance");
- Create aVimServiceobject to obtain aVimPortbinding provider. TheBindingProviderobject provides access to the protocol fields in request/response messages. Retrieve the request context which will be used for processing message requests.TheVimServiceLocatorandVimPortTypeobjects provide access to vSphere servers. ThegetVimPortmethod returns aVimPortTypeobject that provides access to the vSphere API methods.vimService = new VimService(); vimPort = vimService.getVimPort(); Map<String, Object> ctxt = ((BindingProvider) vimPort).getRequestContext();
- Store the Server URL in the request context and specifytrueto maintain the connection between the client and server. The client API will include the server's HTTP cookie in its requests to maintain the session. If you do not set this to true, the server will start a new session with each request.ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
- Retrieve theServiceInstancecontent (theServiceContentdata object) and log in to the server.serviceContent = vimPort.retrieveServiceContent(SVC_INST_REF); vimPort.login(serviceContent.getSessionManager(), userName, password, null); isConnected = true;