Пример #1
0
      private void DoConnect(String url, String hostName)
      {
          System.Net.ServicePointManager.CertificatePolicy = new CertPolicy();
         _svcRef = new ManagedObjectReference();
         _svcRef.type = "ServiceInstance";
         _svcRef.Value = "ServiceInstance";
         _service = new VimService();
         _service.Url = url;
         _service.Timeout = 600000; //The value can be set to some higher value also.
         _service.CookieContainer = new System.Net.CookieContainer();
         _sic = _service.RetrieveServiceContent(_svcRef);

         if (_sic.sessionManager != null)
         {
            Boolean flag = true;
            SSPIClientCredential clientCred = new SSPIClientCredential(SSPIClientCredential.Package.Negotiate);
            SSPIClientContext clientContext = new SSPIClientContext(clientCred,
                                                                    "",
                                                                    SSPIClientContext.ContextAttributeFlags.None);
            
            //ManagedObjectReference hostmor = _service.FindByIp(_sic.searchIndex, null,
            //                                                   hostName,false);
             while (flag)
            {
               try
               {
                  _service.LoginBySSPI(_sic.sessionManager, Convert.ToBase64String(clientContext.Token), "en");
                  flag = false;
               }
               catch (Exception e)
               {
                  SoapException se = (SoapException)e;
                  clientContext.Initialize(Convert.FromBase64String(se.Detail.InnerText));
                  try
                  {
                     Console.WriteLine("Time " + _service.CurrentTime(_svcRef));
                     flag = false;
                  }
                  catch (Exception ex)
                  {
                     flag = true;
                  }
               }
            }                    
            //HostServiceTicket cimTicket = _service.AcquireCimServicesTicket(hostmor);
            //String sessionId = cimTicket.sessionId;
            //GetComputeSystem(sessionId, hostName);
         }
      }
 /// <summary>
 /// Simple method to query and print the server time
 /// </summary>
 public void PrintTime()
 {
     Console.WriteLine("Getting server time!");
     Console.WriteLine("Server time is {0}", _service.CurrentTime(_svcRef));
 }