WCF Performance in Silverlight


  • When testing silverlight I noticed a big difference in WCF communication between Silverlight and a "Windows application". I Created two very simple test applications both calling the same webservice (WCF hosted in console application with basichttp binding). I measure both timings and notice a difference of factor 20. To eliminate outside influences the server and both clients run on the same machine. The code inside the service is very simple and does not perform any sql query or whatsoever. I also perform a 'warm up' to avoid 'first call delays'.

    When calling the wcf server with the Windows application my timings are around 3ms  (as expected).
    Calling the same wcf server from a Silverlight application results in timings around 60ms.

    I already tested the Silverlight application in Firefox, Google Chrome and OOB (Out Of Browser) but it didn't make any difference. Packet sniffing showed no difference in number of calls (for authentication) between the Silverlight and the Windows application.

    Any suggestions?

    Thursday, August 13, 2009 11:00 AM


All replies

  • How do you measure the time? On the client or on the server?

    Does your Silverlight application perform concurrent web service calls?

    Have you tried taking a measurement while using the HttpClient stack as oppoed to the browser HTTP stack in your client application?

    Thursday, August 13, 2009 4:12 PM
  • In Silverlight I measure:

    void btnTestConnection_Click(object sender, RoutedEventArgs e)
        var siteService = new SiteService.SiteServiceClient();
        siteService.LoadSiteInfoCompleted += new EventHandler(siteService_LoadSiteInfoCompleted);
        int start = Environment.TickCount;
        for (int i = 0; i < 5; i++)
    void siteService_LoadSiteInfoCompleted(object sender, NxgWCFTest_SL.SiteService.LoadSiteInfoCompletedEventArgs e)
        int diff = Environment.TickCount - (int)e.UserState;
        lbInfo.Text += " " + diff + "ms.";
    In the Windows application I use:
    var siteService = new SiteService.SiteServiceClient();
    for (int i = 0; i < 5; i++)
        var stopwatch = new Stopwatch();
        var response = siteService.LoadSiteInfo();
        Console.WriteLine("Call took " + stopwatch.ElapsedMilliseconds + " ms.");

    Next steps:
    We also tested Silverlight with sequential (instead of concurrent) calls but that did not make any difference. The next thing I will try is using HttpClient and custom sockets. I will post the results asap.

    Friday, August 14, 2009 3:15 AM
  • I have the same problem. Have you tested with httprequest and sockets? What was the result?

    Wednesday, August 19, 2009 4:46 AM
  • I performed tests both with sockets and webclient. Webclient had the same problem of a ~60 msec delay, but sockets where much faster. The problem with using sockets is that it only can open a socket to a limited number of ports (not including 80). So both webclient and socket are not useable as a alternative to wcf.

    Wednesday, August 19, 2009 9:27 AM
  • My experience is the same. How can we make WCF services more effiecient? No matter what binding....

    Wednesday, August 19, 2009 4:46 PM
  • This phenomenon is related to the threading behavior of WCF calls initated from the UI thread of a Silverlight application. For a detailed description and a way to improve latency of concurrent WCF calls please check out

    Wednesday, August 19, 2009 6:25 PM
  • I need to execute some sequential calls but noticed a large delay (~ 100ms) until the next  call is executed. The next call is started in the Completed handler of the previous call.

    Using a workerthread for the first call did not improve the performance. Also no performance improvement when executing in a more synchronous way; executing all calls from the workerthread but synchronize the calls using ManualResetEvents set in the Completed handlerI  

    The result of previous calls are used in the next calls, so I can not use concurrent calls.

    Does anybody has some more options to improve this sequential call performance ?

    edit: created new post for this question:




    Wednesday, August 26, 2009 6:12 AM
  • I'm having a major problem when MediaElement is streaming music (I haven't tried this problem with video) and running many story boards.

    So there are three systems involved, 1) MediaElement, 2) High demand animations and 3) WCF.

    I can run 1 and 3 together or 2 and 3 and everything works "fine".  But as soon as I try to run them all together then the development server stops getting anything via WCF.  (I'm not willing to put this up on my "rent a server" because I don't want someone visiting and seeing this problem.  So, it is possible that calling a remote server will "solve" this.)

    I put the WCF client side calls in a thread - as describe above - but it doesn't help at all.  I wait 20-30 seconds and nothing gets through. The client side debug output window shows that I'm making requests but the server never sees them - per it's output window.  (I'm sure it doesn't help that I keep pushing stuff out but something should get through.)

    Moderate demand animations allow WCF to get things through to the server.  I guess, for the time being, it's going to be trial and error - on a low resource machine - to find the limits.

    I would expect that each of these systems would degrade at relatively the same rate but that doesn't happen.  The music plays without a stutter and the animations cruise right along as though nothing is wrong.  But WCF comes to a complete halt.

    Any suggestions would be appreciated.


    Friday, September 25, 2009 4:01 PM
  • So, it is possible that calling a remote server will "solve" this

    I put out a temporary webservice on my remote server and started posting to it to test this.

    I put a break point on the async call and a break point on the completed event and then watched Fiddler.

    When I press F5 it can take 15 seconds before Fiddler sees the outbound traffic.  Then about 10 seconds before Fiddler sees it comming back (at that point it might take a second - all subjective - before the completed event is hit).  Without the animations running the complete round trip takes less than a second.

    So I'm beginning to think that it has nothing to do with Silverlight / WCF.  My whole PC is running very stressed during this test.  I think it might be something to do with the network stack.  I don't know what happens after the async call is made via my service reference so I guess I have to leave it there.  (Fiddler must be "stressed" too so I don't know how to factor that in...)

    Oh yeh, I'm only allowing one call at a time, I'm not issuing another until the previous completes.

    Friday, September 25, 2009 8:52 PM
  • I encountered 3 seconds delay on every single web service call as described in

    There are no concurrent calls. Is this realted to this issue ?


    Tuesday, November 10, 2009 12:20 PM