When you generate the .NET stubs to run C# samples in the SDK, you get best performance if you pre-compile the XML serializers into separate DLLs. The procedure in Build the C# vSphere DLLs describes how to pre-compile the XML serializers and modify the class declaration to use a pre-compiled serializer DLL. The result of these changes is to decrease initialization time when you instantiate the VimService class.
You can choose to script the procedure to build the DLLs. Using a script reduces the chance of errors and is faster than doing the procedure manually. This example script illustrates the procedure to build the DLLs with pre-compiled serializers.
This example script requires several environment variables to locate the source files and tools. The script also requires that you install a SED utility, which it uses to make the necessary changes to the C# source. You can find SED for Windows, or other capable tools, on the Web.
Example: Example Script To Build C# DLLs
@echo off
if "%WS_SDK_HOME%"=="" (
echo Set WS_SDK_HOME=^<absolute path to vsphere-ws directory of unzipped SDK^>.
goto end
)
if "%WSDL_HOME%"=="" (
rem This long line wraps:
echo Set WSDL_HOME=%WS_SDK_HOME%\vsphere-ws\wsdl\vim25 ^(or absolute path to directory containing vim and vim25 WSDL subdirectories^).
goto end
)
if "%SED_HOME%"=="" (
echo Install SED and Set SED_HOME=^<absolute path to directory containing sed.exe^>.
goto end
)
if not exist %WS_SDK_HOME%\vsphere-ws\dotnet\cs\samples (
rem This long line wraps:
   echo Did not find %WS_SDK_HOME%\vsphere-ws\dotnet\cs\samples directory. Please unzip SDK files and check WS_SDK_HOME setting.
goto end
)
cd %WS_SDK_HOME%\vsphere-ws\dotnet\cs\samples
 
echo "Building Vim25Api namespace DLLs..."
if exist VimService.cs* del VimService.cs*
rem This long line wraps:
wsewsdl3.exe /n:Vim25Api /type:webClient /l:CS "%WSDL_HOME%\vim.wsdl" "%WSDL_HOME%\vimService.wsdl"
if exist Vim25Service.dll del Vim25Service.dll
rem This long line wraps:
csc.exe /t:library /out:Vim25Service.dll /r:"%WSE_HOME%\Microsoft.Web.Services3.dll" VimService.cs
echo "...Generating Vim25Api serializers..."
if exist Vim25Service.XmlSerializers.dll del Vim25Service.XmlSerializers.dll
sgen /p Vim25Service.dll
rem These 2 long SED lines wrap:
"%SED_HOME%"\sed.exe "s#\[System.Xml.Serialization.XmlIncludeAttribute#//&#" <VimService.cs >VimService.cs.temp
"%SED_HOME%"\sed.exe "s#public partial class VimService #\[System.Xml.Serialization.XmlSerializerAssemblyAttribute\(AssemblyName = \"Vim25Service.XmlSerializers\")\]\n &#" <VimService.cs.temp >VimService.cs
rem This long line wraps:
csc.exe /t:library /out:Vim25Service.dll /r:"%WSE_HOME%\Microsoft.Web.Services3.dll" VimService.cs
 
echo "Copying DLLs into library directory..."
copy Vim25Service*.dll lib
:end