Accessing the vSphere Server from a Web Services Client

The steps that use the vSphere Web Services API to create the connection are:
  1. Create a managed object reference for the
    ServiceInstance
    object on the server.
    ManagedObjectReference SVC_INST_REF = new ManagedObjectReference(); SVC_INST_REF.setType("ServiceInstance"); SVC_INST_REF.setValue("ServiceInstance");
  2. Create a
    VimService
    object to obtain a
    VimPort
    binding provider. The
    BindingProvider
    object provides access to the protocol fields in request/response messages. Retrieve the request context which will be used for processing message requests.
    The
    VimServiceLocator
    and
    VimPortType
    objects provide access to vSphere servers. The
    getVimPort
    method returns a
    VimPortType
    object that provides access to the vSphere API methods.
    vimService = new VimService(); vimPort = vimService.getVimPort(); Map<String, Object> ctxt = ((BindingProvider) vimPort).getRequestContext();
  3. Store the Server URL in the request context and specify
    true
    to 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);
  4. Retrieve the
    ServiceInstance
    content (the
    ServiceContent
    data object) and log in to the server.
    serviceContent = vimPort.retrieveServiceContent(SVC_INST_REF); vimPort.login(serviceContent.getSessionManager(), userName, password, null); isConnected = true;