Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 8th, 2014, 10:57 PM   #1
Thaidog
Newbie
 
Join Date: Sep 2004
Posts: 16
Rep Power: 0 Thaidog is on a distinguished road
Question 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:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VMware.Vim;

namespace vmwaretest
{
    class Program
    {
        static void Main(string[] args)
        {
            VimClient c = new VimClient();
            ServiceContent sc = c.Connect("server01.dom1");
            UserSession us = c.Login("xxxxxx", "xxxxxxx");

            IList<VMware.Vim.EntityViewBase> vms = c.FindEntityViews(typeof(VMware.Vim.VirtualMachine), null, null, null);
            foreach (VMware.Vim.EntityViewBase tmp in vms)
            {
                VMware.Vim.VirtualMachine vm = (VMware.Vim.VirtualMachine)tmp;
                Console.WriteLine((bool)(vm.Guest.GuestState.Equals("running") ? true : false));
                Console.WriteLine(new Uri(vm.Guest.IpAddress != null ? vm.Guest.IpAddress : "0.0.0.0"));
                Console.WriteLine((string)vm.Client.ServiceUrl);
                Console.WriteLine(vm.Guest.HostName != null ? (string)vm.Guest.HostName : "");
                Console.WriteLine("----------------");
            }
        }
    }
}

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

Here is the full exception detail:

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

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

Anyone have any ideas as to what I am doing wrong?
Thaidog is offline   Reply With Quote
Old Dec 8th, 2014, 11:56 PM   #2
Thaidog
Newbie
 
Join Date: Sep 2004
Posts: 16
Rep Power: 0 Thaidog is on a distinguished road
Re: Having trouble passing variables to basic C# console app

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.
Thaidog is offline   Reply With Quote
Reply

Bookmarks

Tags
.net, c#, vmware

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Variables from one PHP file to Another supermoose37 PHP 1 May 8th, 2011 7:05 PM
Adding a GUI window to a console app. WarPhalange C++ 2 Jan 13th, 2011 11:55 PM
console window in win app CppBuilder2006 C++ 11 Mar 4th, 2009 9:59 PM
console app with wxWidgets rwm C++ 7 Sep 4th, 2007 10:44 AM
Passing variables using sessions k4pil PHP 0 Feb 19th, 2006 3:08 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:42 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC