Having trouble passing variables to basic C# console app

    • Having trouble passing variables to basic C# console app

      I am trying to pass an ip, username and password in a simple test app that use the vmware api:

      Brainfuck Source Code

      1. using System;
      2. using System.Collections.Generic;
      3. using System.Linq;
      4. using System.Text;
      5. using System.Threading.Tasks;
      6. using VMware.Vim;
      7. namespace vmwaretest
      8. {
      9. class Program
      10. {
      11. static void Main(string[] args)
      12. {
      13. VimClient c = new VimClient();
      14. ServiceContent sc = c.Connect("server01.dom1");
      15. UserSession us = c.Login("xxxxxx", "xxxxxxx");
      16. IList<VMware.Vim.EntityViewBase> vms = c.FindEntityViews(typeof(VMware.Vim.VirtualMachine), null, null, null);
      17. foreach (VMware.Vim.EntityViewBase tmp in vms)
      18. {
      19. VMware.Vim.VirtualMachine vm = (VMware.Vim.VirtualMachine)tmp;
      20. Console.WriteLine((bool)(vm.Guest.GuestState.Equals("running") ? true : false));
      21. Console.WriteLine(new Uri(vm.Guest.IpAddress != null ? vm.Guest.IpAddress : "0.0.0.0"));
      22. Console.WriteLine((string)vm.Client.ServiceUrl);
      23. Console.WriteLine(vm.Guest.HostName != null ? (string)vm.Guest.HostName : "");
      24. Console.WriteLine("----------------");
      25. }
      26. }
      27. }
      28. }
      Display All


      This fails with an error: ServiceContent sc = c.Connect("server01.dom1"); in VS2013

      Here is the full exception detail:

      Source Code

      1. System.UriFormatException was unhandled
      2. HResult=-2146233033
      3. Message=Invalid URI: The format of the URI could not be determined.
      4. Source=System
      5. StackTrace:
      6. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
      7. at System.Uri..ctor(String uriString)
      8. at VMware.Vim.VersionUtils.GetVIServerSupportedVersions(String serviceUrl)
      9. at VMware.Vim.VersionUtils.GetVIServerVersion(String serviceUrl)
      10. at VMware.Vim.VimClient.Connect()
      11. at VMware.Vim.VimClient.Connect(String serviceUrl)
      12. at vmwaretest.Program.Main(String[] args) in c:\Users\Administrator\Documents\Visual Studio 2013\Projects\vmwaretest\vmwaretest\Program.cs:line 15
      13. at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
      14. at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
      15. at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      16. at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
      17. at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
      18. at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
      19. at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      20. at System.Threading.ThreadHelper.ThreadStart()
      21. InnerException:
      Display All


      Changing the server name to "http://server01.dom1/sdk" does not work either.

      Anyone have any ideas as to what I am doing wrong?
    • Never mind on the connection string. That does work with hard coding the variables in the connection method. I needed to add console.read(); for the last line of the main to see the program run which helped me figure out the problem. It would be nice to know how to use an encrypted session file to keep from hard coding these credentials in to the program however.