When you use the VMware Infrastructure SDK 2.0 from .NET, the VimService class takes a long time to instantiate. Essentially, the _service = new VimService(); statement can take as long as 50 seconds to execute. The following instructions allow you to address issues for Microsoft Visual Studio 2005 using .NET 2.0. You must upgrade your environment, if you have older versions such as Visual Studio 2003 or .NET 1.1.
Important: This patch will work only for the VI API 2.0.1 release.
The Microsoft .NET XmlSerializer uses the System.Xml.Serialization.* attributes, which annotate the proxy classes, to generate serialization code in runtime. When the proxy classes are many and large, as is the case in the VimService.cs code, generating serialization code can take a long time.
This is a known problem with the Microsoft .NET serializer. The following MSDN links provide methods for solving this problem:
The above references do not describe the complete solution. They focus on how to pregenerate the XML serialization code.
Implementing the steps of this KB article will decrease the vimService instantiation call. Even after you have made the fix, the time to instantiate the VimService class for the first time is not instantaneous (1.5 seconds). Empirical observation shows that the majority of the time is due to processing the SoapDocumentMethodAttribute attributes. It is unclear how this time can be reduced. The pregenerated XmlSerializer assembly does not account for the SOAP-related attributes, so these attributes need to remain in the code. Fortunately, only the first instantiation of the VimService class for that application takes long. If the extra 1.5 seconds creates a problem, you can do a dummy instantiation of this class at the beginning of the application to improve the user's login time.
This KB describes two methods to address this problem. Alternative 1 provides a script that patches the generated stub files to work around the problem. Alternative 2 allows developers to implement the various steps on their own.
A single step solution in the form of a patch that optimizes the C# stubs is available for SDK 2.0.1. This solution does not modify the samples subdirectories and backs up the files that are changed with a timestamp.
This patch file modifies the Build2005.cmd to use a script genvimstubs.cmd to patch the C# stubs and compile the generated stubs. genvimstubs.cmd uses a .NET utility OptimizeWsStubs.exe to patch the C# stubs. The patch file is available for SDK 2.0.1.
The updated Build2005.cmd file uses the genvimstubs.cmd script to:
Use the patched Build2005.cmd to regenerate the .NET Stubs that are optimized and improve startup time. genvimstubs.cmd and OptimizeWsStubs.exe allows you to generate stubs with your choice of namespaces and filenames.
Do not perform this step if you have already run the new Build2005.cmd. The solution described below allows you to manually patch the generated stubs in VimService2005.dll by
Note: In the SDK C# samples, the DLL generated by default by Build2005.cmd for Visual Studio 2005 is named VimService2005.dll. If you want to avoid removing and re-adding DLL references, make sure you use VimService2005.dll where VimService.dll is used in the instructions below. You may also use any other DLL (or Assembly) name instead of VimService.dll, however, you must change the filename appropriately.
To create a serializer assembly:
This command outputs the VimService2005.XmlSerializers.dll file in the current directory.
You should end up with something like this:
// ... Some code here ...
[System.Xml.Serialization.XmlSerializerAssemblyAttribute(AssemblyName = "VimService2005.XmlSerializers")]
public partial class VimService : System.Web.Services.Protocols.SoapHttpClientProtocol {
// ... More code here.
Regenerate the VimService2005.dll library with the following command:
csc /t:library /out:VimService2005.dll VimService.cs
Ensure your application references the new VimService2005.dll library.
Run your application and verify that the VimService object instantiation time is reduced.