VMware {code} Community
Schorschi
Expert
Expert

Doing nasty things with VMware VI SDK 2.5 via Visual Studio 2008

This thread is to document the changes needed to use Virtual Studio 2008 with VMware VI SDK 2.5. The various examples seen in Google are Virtual Studio 2003 or older, which, unfortunately, there are some differences between VS2003 and VS2008. This example also is based on .NET 3.5, which is core to VS2008. This example was done on Windows XP SP2, fully patched as of 12/18/2007.

Compiling and Linking WSDL files...

1) Install Visual Studio 2008

2) Download VMware SDK

3) Unzip the VMware SDK zip. In this example... for a folder called SDK, at path "D:\Development (VMware Virtual Infrastructure SDK)\SDK"

4) Execute the wsdl.exe for C# and VB .NET. In this example, wsdl.exe, at path "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\wsdl.exe" Note: /l: (L as in language) for the VB .NET example. The wsdl.exe defaults to C# .NET.

a) For VB .NET... in the "vim" directory under SDK\wsdl, D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim>"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\wsdl.exe" /l:VB /o:VimApi.vb /n:VimApi vim.wsdl vimservice.wsdl
b) For C# .NET... in the "vim" directory under SDK\wsdl, D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim>"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\wsdl.exe" /o:VimApi.cs /n:VimApi vim.wsdl vimservice.wsdl
c) Repeat 'a' and 'b' steps in the "vim25" directory under SDK\wsdl.
d) And thus, D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim>"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\wsdl.exe" /l:VB /o:VimApi25.vb /n:VimApi25 vim.wsdl vimservice.wsdl
e) Thus, D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim>"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\wsdl.exe" /o:VimApi25.cs /n:VimApi25 vim.wsdl vimservice.wsdl

5) Now that we have the object classes, Part II will be small application that does something useful!

For my examples above...

For "vim"...

11/16/2007 13:05 971,422 vim.wsdl

12/18/2007 06:06 2,077,317 VimApi.cs

12/18/2007 06:12 2,196,589 VimApi.vb

11/16/2007 13:05 558 vimService.wsdl

For "vim25"...

11/16/2007 13:16 1,356,892 vim.wsdl

12/18/2007 06:07 3,230,096 VimApi25.cs

12/18/2007 06:12 3,410,882 VimApi25.vb

11/16/2007 13:16 561 vimService.wsdl

Yes, just posting this information declares my heretic status in the VMware forums, well, cool. Hey, VMware, you need to add a new points label... Heretic. For those of us that go off the official reservation, and don't use Perl.

0 Kudos
8 Replies
Schorschi
Expert
Expert

Well, as I feared, any attempt to use the VimApi25 file for VB .NET as generated above, hangs Virtual Studio 2008. And I do mean hangs it. I have to use Task Manager to kill devenv.exe. Ok VMware, what the heck is going on? Code that crashes the IDE? Wonderful.

0 Kudos
Schorschi
Expert
Expert

Soon as I get the feathers out of my mouth, since I am eating some crow on this... I realized after getting into the details of setting up the development environmnet, it is not recommeded to have the IDE compile the objects inclusive of the project, in fact the hang issue is avoided by precompiling the object DLLs. Digging into the command batch procedure that does this for VS2003 and VS2005, it appears to be straight-forward. So, below is the steps to generate the object DLLs. Note, I did not rerun the optimize stubs executable since it may be VS2003 or VS2005 specific, and without its source available, did not want to risk corrupting the DLLs. VMware will have to support VS2008 at some point, so at that point optimizing the stubs would make sense. After all, this entire thread is ahead of the curve for VMware based on VS2008.

Create the based on .NET 2.0 complaint DLLs, specifc to C# .NET code, this is fine, since the DLL can be called from VB .NET or C# .NET as needed. Including the 2008 in the file name was done to make it obvious what these DLLs are based on...

D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim>"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /out:vimApi2008.dll vimApi.cs
D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim25>"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /out:vimApi252008.dll vimApi25.cs

Generate the XML Serialization...

D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim25>"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\sgen.exe" /p /out:"%CD%" vimApi252008.dll
Microsoft (R) Xml Serialization support utility
http://Microsoft (R) .NET Framework, Version 2.0.50727.1432
Copyright (C) Microsoft Corporation. All rights reserved.
Serialization Assembly Name: vimApi252008.XmlSerializers, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
Generated serialization assembly for assembly D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim25\vimapi252008.dll --> 'D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim25\vimApi252008.XmlSerializers.dll'.
D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim>"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\sgen.exe" /p /out:"%CD%" vimApi2008.dll
Microsoft (R) Xml Serialization support utility
http://Microsoft (R) .NET Framework, Version 2.0.50727.1432
Copyright (C) Microsoft Corporation. All rights reserved.
Serialization Assembly Name: vimApi2008.XmlSerializers, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null.
Generated serialization assembly for assembly D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim\vimapi2008.dll --> 'D:\Development (VMware Virtual Infrastructure SDK)\SDK\wsdl\vim\vimApi2008.XmlSerializers.dll'.

The same steps above would be required for .NET 3.5 of ocurse. In that case, adding 35 to the DLL name might also be a good idea.

0 Kudos
Schorschi
Expert
Expert

VMware? Any word on when the SDK will be updated for Visual Studio 2008??!!

0 Kudos
ISYS2
Enthusiast
Enthusiast

I have been using VI SDK 2.5 in VS 2008 for about 3 weeks now with no issues. I generated the attached dlls using the batch file (Alternative 2 here ) and all worked out of the box.

0 Kudos
Schorschi
Expert
Expert

Thanks for the KB. I will try building the DLLs again. Was using the 2005 batch files as a guide and I think I built the DLLs right, but when ever I try to compile and run a .NET project using the new DLLs, Visual Studio 2008 IDE seems to lock up. Maybe I missed something the first time.

0 Kudos
cmwalolo
Contributor
Contributor

The VIMService2005.DLL does not contain the ManagedObject types : ResourcePool, DataStore and so on... as found in the table 5.1 of the Programming Guide.

I compiled on VS2008, I downloaded yours. And I can't do anything with only the ManagerObjectReference => As far as I know with only the reference I do not access to the name and path of the objects as they are in the views.

Maybe i'm missing something ?

Should it be possible to get the right DLL, maybe some compiled with VS2005 ?

Thanks,

Laurent

0 Kudos
tos2k
Expert
Expert

Afaik Datastore is not a predefined type, thats right. Create your own.

datastore is a type for a ManagedObjectReference, MOR.

To a MOR there are several properties assigned, for datastores f.i. you have DatastoreSummary. From these properties, you get the "content", values aso.

Tos2k

0 Kudos
admin
Immortal
Immortal

In vSphere 4, Datastore inherits from ManagedEntity rather than ExtensibleManagedObject (IOW it was promoted to a managed entity rather than an ordinary managed object).

This may explain the problem you're seeing.

0 Kudos