LoginByTokenSample Constructor in a C# Web Services SDK Client

The LoginByTokenSample class constructor creates the following elements to set up access to the vCenter Server.

  • VimService object – Provides access to vSphere API methods and support for security policies and session cookie management. It also stores the vCenter Server URL.
  • CookieContainer – Provides local storage for the vCenter Server session cookie.
  • ManagedObjectReference – Manually created ManagedObjectReference to retrieve a ServiceInstance at the beginning of the session.

The following code fragment shows the LoginByTokenSample constructor.

LoginByTokenSample Constructor

// Global variables
private VimService _service;
private ManagedObjectReference _svcRef;
private ServiceContent _sic;
private string _serverUrl;


public LoginByTokenSample(string serverUrl)
{
    _service = new VimService();
    _service.Url = serverUrl;
    _serverUrl = serverUrl;
    _service.CookieContainer = new System.Net.CookieContainer();
    _svcRef = new ManagedObjectReference();
    _svcRef.type = "ServiceInstance";
    _svcRef.Value = "ServiceInstance";
}