While writing some VMWare SDK/Web Services howto posts as well as some production code in C# I recently ran into an issue where the vimService object was taking upwards for 3 minutes to instantiate.

I figured that I might have messed up on adding the web service reference, so I re-added the web service reference to the project by select “Add Web Reference”, then when it asked for the WSDL location put in our ESX server location. ie. /sdk/vimService?wsdl">/sdk/vimService?wsdl">https://<server>/sdk/vimService?wsdl. Everything should be be good with this right? Wrong… Just by doing this the vimService takes forever to load.

After some researching it turns out that this is somewhat of a known issue, and has to do with the XmlSerialization object in .NET 2.0 and above (Apparently this works fine with .NET 1.1, but that doesn’t really help me out to much :)

In order to use this web service successfully and have acceptable load times, you are going to have to create the proxy DLL manually, and do some modification of the class that gets gen’d from the wsdl.exe. Since I am putting together some howto posts using the VMWare SDK/Web Services I thought I would put together this post, to document the steps to create a workable proxy DLL that can be used in any .NET projects (c# or VB.net)

Here are a couple of video’s to show the response time. I didn’t edit the first video so there is a lot of dead air :)

Accessing the VIMService object (SLOW…..)

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
WIDTH="500" HEIGHT="500" id="slowVMService"></object>

 

Accessing the VIMService object with the modified proxy object. Pretty snappy….

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
WIDTH="400" HEIGHT="330" id="slowVMService"></object>

Step 1. Download and install the VMWare SDK from the following location http://www.vmware.com/download/sdk/. You want to get the SDK titled “VMware Infrastructure SDK Packages”

Step 2. We are going to want to generate a source file from the WSDL files that come included with the SDK. Remember from my earlier comment that you cannot add this as a web reference from Visual Studio or you will suffer from the slow load time). With that being said, we need to navigate to the location of the wsdl files. These should be located in c:<SDKInstalledFolder>sdkwsdlvim25 folder. NOTE: I am assuming here that you are using ESX 2.5 or above. If you are using a lower version be sure to use the wsdl files in the vim folder instead.

To generate the source file issue the following command

wsdl.exe vim.wsdl vimService.wsdl

By default this will create a VimService.cs file in the same directory.

image

Step 3. After we have generated the source file we need to compile that into a library so that the proxy can be used in  visual studio. To compile the source file issue the following command.

csc.exe /t:library /out:VimService.dll VimService.cs

image

Step 4. Here is where is gets a little unusual. After we have created the DLL we are going to need to run a .NET utility called sgen on it.

SideBar: sgen.ee is a tool that comes with the .NET SDK. Running this tool on a specific assembly will create a XML serialization assembly for the the types in the given assembly. This helps improve load performance of said assembly.

To run sgen on the newly created dll, issue the following command.

sgen.exe /p VimService.dll

Note: This process make take a few minutes :)

image

Step 5. The next step in the process is to modify the actual source file that got created from the WSDL.exe command. Using you favorite text editor open up the  vimService.cs file and comment out all lines that start with [System.Xml.Serialization.

You can do a search and replace and search for [System.Xml.Serialization.XmlIncludeAttribute

and replace with

//[System.Xml.Serialization.XmlIncludeAttribute

In the end, you should end up with something like this (Note there are about 3,162 occurrences)

image

image

Step 6. After commenting out the System.Xml.Serialization we are going to need to add an additional attribute on the VimService class in the source file. Open the vimService.cs in your favorite text editor, find the following line
public partial class VimService : System.Web.Services.Protocols.SoapHttpClientProtocol {

and right before it add this

[System.Xml.Serialization.XmlSerializerAssemblyAttribute(AssemblyName = "VimService.XmlSerializers")]

It should resemble the followingimage

This will make your source file ready for compilation again. :)

Step 7. The last step in this process is to recompile the source file once again and create a new library for use within Visual Studio.

Run the following command

csc.exe /t:library /out:VimService.dll VimService.cs

And you should a shiny new dll ready for use within your .NET projects and without the unbearable load times of the vimService object.

image

And with that, I’m OUT!