Building the C# vSphere DLLs
In the vSphere Web Services SDK, VMware supplies sample vSphere clients for Visual Studio 2008. The SDK includes a project (.csproj) file for each sample, and a solution (.sln) file for the whole set of samples. The project files reference the DLLs through which a client communicates with the Web service.
XML Serializers
For best performance, precompile the XML serializers to a separate DLL. If you precompile the XML serializers and modify the class declaration to use the precompiled serializer DLL, the SDK samples require a shorter initialization time when they instantiate the VimService class.
See the MSDN documentation for more details about XML serialization and startup performance.
Build the C# vSphere DLLs
Before you can run the SDK samples, you must build the DLLs that provide common services to the samples.
Prerequisites for Building the C# vSphere DLLs
For an example of how to script this procedure using a Windows batch file, see Scripting the C# DLL Build.
To build the C# vSphere DLLs
1
2
cd %WS_SDK_HOME%\vsphere-ws\dotnet\cs\samples
3
Generate the VimService.cs file from the WSDL, using the following command syntax with the WSE WSDL tool:
wsewsdl3.exe /n:Vim25Api /type:webClient /l:CS %WSDLHOME%\vim.wsdl %WSDLHOME%\vimService.wsdl
This command generates VimService.cs, the default output file, in the current directory, using the Vim25Api namespace.
4
Compile VimService.cs to a library, using the following command syntax:
csc /t:library /out:Vim25Service.dll /r:"%WSE_HOME%\Microsoft.Web.Services3.dll" VimService.cs
This command generates a serializer assembly, a DLL.
5
Use the sgen tool to pregenerate and compile the XML serializers, using the following command syntax:
sgen /p Vim25Service.dll
This command outputs the Vim25Service.XmlSerializers.dll file in the current directory. This DLL file contains pregenerated XML serializer code.
6
[System.Xml.Serialization.XmlIncludeAttribute
Replace occurrences of the string with
// [System.Xml.Serialization.XmlIncludeAttribute
This will prevent .NET from processing the Xml.Serialization.XmlIncludeAttribute attributes that are the main cause of the slow instantiation of the Vim25Service class.
7
Annotate the VimService class in the VimService.cs file that you generated in Step 3, adding this XmlSerializerAssemblyAttribute to point to the location of the XML serializer assembly:
[System.Xml.Serialization.XmlSerializerAssemblyAttribute(AssemblyName = "Vim25Service.XmlSerializers")]
The result should look something like the following example:
// ... Some code here ...
[System.Xml.Serialization.XmlSerializerAssemblyAttribute(AssemblyName = "Vim25Service.XmlSerializers")]
public partial class VimService : Microsoft.Web.Services3.WebServicesClientProtocol {
// ... More code here.
8
Save the modified VimService.cs file.
9
Regenerate the Vim25Service.dll library with the following command syntax:
csc /t:library /out:Vim25Service.dll /r:"%WSE_HOME%\Microsoft.Web.Services3.dll" VimService.cs
10
Copy the generated files Vim25Service.dll and Vim25Service.XmlSerializers.dll to the %SDK_HOME%\vsphere-ws\dotnet\cs\samples\lib directory.
copy Vim25Service*.dll lib