Connections to the server machine require credentials: user name, password, and host name (or IP address). The following code connects to the server and extracts information useful for manipulating a service:

Procedure

  1. Create the service instance moRef:
    ManagedObjectReference svcRef = new ManagedObjectReference();
    svcRef.setType("ServiceInstance");
    svcRef.setValue("ServiceInstance");
  2. Locate the service:
    VimServiceLocator locator = new VimServiceLocator();
    locator.setMaintainSession(true);
    VimPortType serviceConnection = locator.getVimPort("https://your_server/sdk");
  3. Log in to the session manager:
    ServiceInstanceContent serviceContent = serviceConnection.retrieveContent(svcRef);
    ManagedObjectReference sessionManager = serviceInstance.getSessionManager();
    UserSession us = serviceConnection.login(sessionManager, username, password, null);