Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 226551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:31:21+00:00 2026-05-11T19:31:21+00:00

I’m doing some experiments with Microsoft Dynamics CRM. You interact with it through web

  • 0

I’m doing some experiments with Microsoft Dynamics CRM. You interact with it through web services and I have added a Web Reference to my project. The web service interface is very rich, and the generated “Reference.cs” is some 90k loc.

I’m using the web reference in a console application. I often change something, recompile and run. Compilation is fast, but newing up the web service reference is very slow, taking some 15-20 seconds:

CrmService service = new CrmService();

Profiling reveals that all time is spent in the SoapHttpClientProtocol constructor.

The culprit is apparently the fact that the XML serialization code (not included in the 90k loc mentioned above) is generated at run time, before being JIT’ed. This happens during the constructor call. The wait is rather frustrating when playing around and trying things out.

I’ve tried various combinations of sgen.exe, ngen and XGenPlus (which takes several hours and generates 500MB of additional code) but to no avail. I’ve considered implementing a Windows service that have few CrmService instances ready to dish out when needed but that seems excessive.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:31:22+00:00Added an answer on May 11, 2026 at 7:31 pm

    The following is ripped from this thread on the VMWare forums:

    Hi folks,

    We’ve found that sgen.exe does work. It’just that there is a couple of additional steps beyond pre-generating the serializer dll’s that we missed in this thread. Here is the detailed instruction

    PROBLEM

    When using the VIM 2.0 SDK from .NET requires long time to instantiate the VimService class. (The VimService class is the proxy class generated by running ‘wsdl.exe vim.wsdl vimService.wsdl’)

    In other words, the following line of code:

    _service = new VimService();
    

    Could take about 50 seconds to execute.

    CAUSE

    Apparently, the .NET XmlSerializer uses the System.Xml.Serialization.* attributes annotating the proxy classes to generate serialization code in run time. When the proxy classes are many and large, as is the code in VimService.cs, the generation of the serialization code can take a long time.

    SOLUTION

    This is a known problem with how the Microsoft .NET serializer works.

    Here are some references that MSDN provides about solving this problem:

    http://msdn2.microsoft.com/en-us/library/bk3w6240.aspx
    http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializerassemblyattribute.aspx

    Unfortunately, none of the above references describe the complete solution to the problem. Instead they focus on how to pre-generate the XML serialization code.

    The complete fix involves the following steps:

    1. Create an assembly (a DLL) with the pre-generated XML serializer code

    2. Remove all references to System.Xml.Serialization.* attributes from the proxy code (i.e. from the VimService.cs file)

    3. Annotate the main proxy class with the XmlSerializerAssemblyAttribute to point it to where the XML serializer assembly is.

    Skipping step 2 leads to only 20% improvement in the instantiation time for the VimService class. Skipping either step 1 or 3 leads to incorrect code. With all three steps 98% improvement is achieved.

    Here are step-by-step instructions:

    Before you begin, makes sure you are using .NET verison 2.0 tools. This solution will not work with version 1.1 of .NET because the sgen tool and the XmlSerializationAssemblyAttribute are only available in version 2.0 of .NET

    1. Generate the VimService.cs file from the WSDL, using wsdl.exe:

      wsdl.exe vim.wsdl vimService.wsdl

      This will output the VimService.cs file in the current directory

    2. Compile VimService.cs into a library

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

    3. Use the sgen tool to pre-generate and compile the XML serializers:

      sgen /p VimService.dll

      This will output the VimService.XmlSerializers.dll in the current directory

    4. Go back to the VimService.cs file and remove all System.Xml.Serialization.* attributes. Because the code code is large, the best way to achieve that is by using some regular expression substitution tool. Be careful as you do this because not all attributes appear on a line by themselves. Some are in-lined as part of a method declaration.

      If you find this step difficult, here is a simplified way of doing it:

      Assuming you are writing C#, do a global replace on the following string:

      [System.Xml.Serialization.XmlIncludeAttribute

      and replace it with:

      // [System.Xml.Serialization.XmlIncludeAttribute

      This will get rid of the Xml.Serialization attributes that are the biggest culprits for the slowdown by commenting them out. If you are using some other .NET language, just modify the replaced string to be prefix-commented according to the syntax of that language. This simplified approach will get you most of the speedup that you can get. Removing the rest of the Xml.Serialization attributes only achieves an extra 0.2 sec speedup.

    5. Add the following attribute to the VimService class in VimService.cs:

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

      You should end up with something like this:

      // ... Some code here ...
      [System.Xml.Serialization.XmlSerializerAssemblyAttribute(AssemblyName = "VimService.XmlSerializers")]
      public partial class VimService : System.Web.Services.Protocols.SoapHttpClientProtocol {
      // ... More code here

    6. Regenerate VimSerice.dll library by

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

    7. Now, from your application, you can add a reference to VimSerice.dll library.

    8. Run your application and verify that VimService object instanciation time is reduced.

    ADDITIONAL NOTES

    The sgen tool is a bit of a black box and its behavior varies depending on what you have in your Machine.config file. For example, by default it is supposed to ouptut optimized non-debug code, but that is not always the case. To get some visibility into the tool, use the /k flag in step 3, which will cause it to keep all its temporary generated files, including the source files and command line option files it generated.

    Even after the above fix the time it takes to instantiate the VimService class for the first time is not instantaneous (1.5 sec). Based on empirical observation, it appears that the majority of the remaining time is due to processing the SoapDocumentMethodAttribute attributes. At this point it is unclear how this time can be reduced. The pre-generated XmlSerializer assembly does not account for the SOAP-related attributes, so these attributes need to remain in the code. The good news is that only the first instantiation of the VimService class for that app takes long. So if the extra 1.5 seconds are a problem, one could try to do a dummy instantiation of this class at the beginning of the application as a means to improve user experience of login time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 208k
  • Answers 208k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is due to execute-as-user scoping - context switching to… May 12, 2026 at 9:38 pm
  • Editorial Team
    Editorial Team added an answer Check this http://iphoneized.com/2009/11/18-mobile-frameworks-development-tools-creating-iphone-apps/ May 12, 2026 at 9:38 pm
  • Editorial Team
    Editorial Team added an answer Your script is run before the a element exists and… May 12, 2026 at 9:38 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.