Delay on first call to web service

As a learning experience, I've written a Windows Forms app which accesses the xmethods StockQuote web service:

http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl

(I'm using .NET 2.0 and Visual Studio 2005.)  The (synchronous) calls to the getQuote method of the service take place in the DoWork handler of a BackgroundWorker.  It takes 10 seconds or more for the first call to getQuote to complete; all subsequent calls complete much more quickly. The delay is not affected by the presence or absence of the MyApp.XmlSerializers.dll generated by the compiler.  I know from accessing the same web service in Python that the delay is not in the web service itself.

So: any ideas on how to remove this delay

Thanks.

Greg Chapman

 



Answer this question

Delay on first call to web service

  • Richard Berg MSFT

    Have a look on the points to improve the Web Service Performance:< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

          1)       Always prefer primitive types for Web service parameters.

    2)       Consider input validation for costly Web methods.

    3)       Implement the approach of caching.

    4)       Consider approaches for bulk data transfer and attachments.

    5)       Avoid calling local Web Services.

    6)       Use the OneWay attribute if you do not require a response.

    7)       Prefer primitive parameter types.

    8)       Use buffering.

    9)       Consider caching responses.

    10)   Reduce round trips.       

     

     



  • Ganeshm

    Unfortunately, the link is broken.  It results in the error message "The file '/.net/webservices.aspx' does not exist."  Do you remember the title of the article so I can search for it on codeproject.com

    Thanks.

    Greg Chapman


  • Adak

    Hi  ,

    Are you invoking the web service dynamically or statically If it is a dynamic invocation , the first call to the web service would be slow.

    Please try implementing statically.

    thanks
    bali


  • ku19832001

    Well, I just did some debugging using disassembly and the call stack and it turns out the delay is from something I don't understand at all.  WebRequest.DefaultWebProxy is set to some kind of proxy which the CRL attempts to use.  Down in the code as the CRL attempts to use it, there is a call to AutoWebProxyScriptEngine.SafeDetectAutoProxyUrl. This method is actually called twice.  It declares a SafeGlobalFree struct variable.  The constructor for this struct runs fine up until the ret at the end, and then there is a multi-second delay before the disassembly window moves back to SafeDetectAutoProxyUrl.  So obviously there's some magic going on with SafeHandles here.

    Anyway, I set WebRequest.DefaultWebProxy to null in my Main method, and now the delay is gone.

    If any of this suggests a misconfigured system, please let me know.  I just installed VS2005 and .Net 2.0 a couple of days ago.  I previously had the .Net Beta 2 installed, but I uninstalled it before installing VS.  Otherwise, I have a (I think) fairly standard Windows XP Pro. SP 2 system here.

    Anyway, thanks for your help.

    Greg Chapman

     


  • Kousay

    Okay, it appears I was hitting a known delay in DHCP web proxy auto-detect.  Here's a blog post:

    http://spaces.msn.com/members/drisa/Blog/cns!1p9yz6owxXl-uIlyqIZXkCrg!352.entry

    There's a reference to a Knowlege Base article and fix which apparently is not yet public (I also failed to find it with a knowledge base search).

    In the meantime, there's this apparently related Knowledge Base article:

    http://support.microsoft.com/kb/220902/en-us

    and the fix suggested there (unchecking "Automatically detect settings") works for me (without setting DefaultWebProxy to null).

    So I guess that resolves things for now.

    Greg Chapman

     


  • kexh

    Try to the following link - it might help you

    www.codeproject.com/.net/webservices.aspx

    thanks

    maulik.soni



  • gjc_vp

    My previous post was pretty badly wrong on the cause of the delay.  The delay appears to be taking place in the unmanaged routine WinHttpDetectAutoProxyConfigUrl.  This routine apparently calls the constructor for SafeGlobalFree (which is a class, not a struct, another dumb mistake).  The constructor is in managed code, so the debugger traces through it, but then control goes back to the unmanaged routine which does something which takes a long time.  WinHttpDetectAutoProxyConfigUrl is documented on MSDN with a reference to a document describing the Web Proxy Auto-Discovery Protocol.  I suppose the real answer to this problem (aside from just avoiding proxies altogether) is in that document.

    Greg Chapman

     


  • Delay on first call to web service