What’s new in WCF 4.5? Improved streaming in IIS hosting

January 17, 2012


As promised in my previous post, I’m continuing my mission to inform you of new changes in WCF 4.5.

This is the ninth post in the WCF 4.5 series. This post continues the previous posts on web-hosting features, and this time it is about the improved streaming capabilities of WCF when it is hosted in IIS.

Previous posts:

1. What’s new in WCF 4.5? let’s start with WCF configuration

2. What’s new in WCF 4.5? a single WSDL file

3. What’s new in WCF 4.5? Configuration tooltips and intellisense in config files

4. What’s new in WCF 4.5? Configuration validations

5. What’s new in WCF 4.5? Multiple authentication support on a single endpoint in IIS

6. What’s new in WCF 4.5? Automatic HTTPS endpoint for IIS

7. What’s new in WCF 4.5? BasicHttpsBinding

8. What’s new in WCF 4.5? Changed default for ASP.NET compatibility mode

If you’ve ever tried creating a WCF service that uses streamed requests (for example a file upload service) and host it in IIS, you may have noticed a strange behavior in your WCF service – it would seem that WCF is late in receiving the request, as if it was entirely loaded into the memory, and then passed to WCF. So is it streamed? or is it actually buffered? well, it’s both.

When you host a WCF service in IIS you also get a bit of the ASP.NET pipeline on the side, even if you don’t use the ASP.NET compatibility mode, this is documented in the WCF Services and ASP.NET article on MSDN (look for the part about the PostAuthenticateRequest event). In .NET 4, there is a design flaw in ASP.NET which causes the requests sent to WCF to be buffered in ASP.NET. This buffering behavior causes several major side-effects:

1. There is a latency between the time the streamed message is received by ASP.NET and the time the WCF service method is actually invoked.

2. There is some memory consumption due to the buffering – the exact amount of memory consumed depends on the size of the message sent by the client, but it can even get to several hundred MBs if you increase the MaxRequestLength of ASP.NET, the MaxAllowedContentLength of IIS 7, and of course the MaxReceivedMessageSize and MaxBufferSize of WCF.

3. When ASP.NET buffers the request, it uses both memory and disk. The requestLengthDiskThreshold configuration setting of ASP.NET controls when ASP.NET starts to use the disk. If you upload multiple files to WCF at once, you will start to see some delays due to multiple files being written to the disk at once. BTW, the files are written to an “upload” folder under the web application’s temporary asp.net folder (under c:\windows\Microsoft.NET\Framework\vX.X.XXXX\Temporary ASP.NET Files\) and are removed after the request is handled.

To show this behavior, I have created a client application that uploads a 500MB file to a WCF service. The WCF service is hosted in IIS and is set to a streamed request (you can download the StreamingInIIS sample solution from here). The following output shows some information about the time it took for the service to receive and handle the request, and the consumed memory:

1 Client started upload on 17/01/2012 19:03:25
2 Available memory before starting is: 2701MB
3 Client finished upload on 17/01/2012 19:03:44
4 Available memory after finishing is: 2699MB
5 Available memory on ASP.NET is: 2701MB
6 ASP.NET received upload at: 17/01/2012 19:03:28
7 Available memory on WCF is: 2122MB
8 WCF started receiving file at: 17/01/2012 19:03:38
9 WCF finished receiving file at: 17/01/2012 19:03:43
File size is: 524288000
Press any key to continue . . .

Some things to note about these results:

1. Client started / Client finished (line 1+3) – the total time the client waited for the service was 19 seconds; this includes the upload time, the buffering time of ASP.NET, and the time WCF handled the received stream.

2. ASP.NET started receiving the stream 3 seconds after the client began sending it (line 6).

3. WCF started receiving the stream 10 seconds after ASP.NET received started receiving it, and a total of 13 seconds from the time the client started sending it (line 8). In total, it took WCF 5 seconds to read the entire stream from ASP.NET (line 8+9).

4. Before the client sent the message, the available memory in the machine was 2701MB, which is also the available memory when ASP.NET first received the message. By the time WCF got the request and started handling it, the available memory was 2122MB – about 580MB were consumed from the memory for this operation (lines 2, 5, and 7).

5. As for the generated temp file, here is a screenshot of the temporary ASP.NET folder content:


Note: to show the ASP.NET information I used the ASP.NET compatibility mode. You can turn it off in the sample code if you want to verify that the problem also exists when we don’t use the compatibility mode (look at the difference between the time the client sent the request and the time WCF actually started handling the request – there should be a big latency).

So we get that WCF 4 doesn’t handle well streamed content over IIS, but what about WCF 4.5? what has changed?

In WCF 4.5 this just doesn’t happen – with .NET 4.5, ASP.NET doesn’t buffer the request, but rather forwards it directly to WCF, so we don’t get any latency, no memory consumption, and no disk usage.

Want to see some proof? I ran the same demo code in Windows Server 8 with WCF 4.5 over IIS. I used a smaller file size (200MB), since this is a VM with less memory, however you can still see the difference quite clearly:

1 Client started upload on 11/27/2011 7:23:18 AM
2 Available memory before starting is: 942MB
3 Client finished upload on 11/27/2011 7:23:46 AM
4 Available memory after finishing is: 942MB
5 Available memory on ASP.NET is: 941MB
6 ASP.NET received upload at: 11/27/2011 7:23:20 AM
7 Available memory on WCF is: 942MB
8 WCF started receiving file at: 11/27/2011 7:23:20 AM
9 WCF finished receiving file at: 11/27/2011 7:23:46 AM
File size is: 209715200
Press any key to continue . . .

First thing to note – memory consumption hasn’t changed throughout the execution – remains steady at ~942MB (lines 2+4+5+7).

As for the latency – WCF received the request at the same time ASP.NET received it (lines 6+8), which is 2 seconds after the client begins sending it.

Oh, and since ASP.NET passed the stream directly to WCF, no temp file was created !!

So there you have it – proper streaming in WCF 4.5 over IIS.

Stay tuned for more posts about the new features of WCF 4.5. You can also follow me on Twitter (@IdoFlatow) to get updates as soon as new posts are published.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



  1. James ManningJanuary 19, 2012 ב 4:48 pm

    Whether OOTB or not, can WCF 4.5 include binding(s) for SPDY?

  2. KonstantinJanuary 27, 2012 ב 6:41 pm

    Is there a workaround for this in WCF 4 and IIS 6/7?

  3. Ido FlatowJanuary 28, 2012 ב 8:48 pm

    James – I haven’t seen any implementation for SPDY, but usually these transport implementation are just a matter or time. Once the protocol is being used widely, someone, somewhere, will create the appropriate transport for WCF.

  4. Ido FlatowJanuary 28, 2012 ב 8:50 pm

    Konstantin: There is no workaround that I know of. It is actually an ASP.NET design bug, not an IIS one, so it is only solved by using WCF 4.5 / ASP.NET 4.5.

  5. DanielJuly 21, 2012 ב 8:58 pm

    I was having same issue on W3K 64bit (VPS siltuoon). When I installed MailEnable (free edition) it auto installed the 64bit version (initially ME complained that I didn’t have DotNet 3.5 installed so I installed that 1st then retried ME install which worked).ME WebMail worked just fine. But then I needed to install some 32bit ActiveX DLLs for my website (ASPUpload was one of them), and to get these working I had to run c:\inetpub\adminscripts\adsutil.vbs set w3svc/AppPools/Enable32bitAppOnWin64 1This got my 32bit DLLs working fine but WebMail stopped with an error like %1 not 32bit Win app (or something like that).So I ran your siltuoon (C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i -enable) and hey presto, WebMail worked again *and* my 32bit DLLs kept on working. IIS6 added (and enabled) the entry ASP.NET v2.0.50727 (32 bit) to the Web Service Extensions list. ASP.NET v2.0.5072 was already in the list (I suspect from the DotNet 3.5 install). I think I also ended up with 2 Default.aspx entries in the Document list for all my websites (I just went and deleted one or both Default.aspx entires from all my websites that didn’t use aspx).This took me several days to resolve. I hope my experience (and Alex’s) helps others.Cheers Alex.Regards, Mark. Sydney, Australia.

  6. FleckSeptember 19, 2012 ב 9:44 pm

    Good way of describing, and good article to take information about my presentation focus, which i
    am going to deliver in college.

  7. SingletonDecember 10, 2012 ב 6:55 pm

    Thanks for sharing your thoughts on Ido Flatow
    WCF MOC HPC Azure Entity Framework Silvelright.

  8. WeedDecember 16, 2012 ב 11:36 am

    Hello, this weekend is good for me, because
    this time i am reading this fantastic educational
    post here at my house.

  9. ScrogginsJanuary 17, 2013 ב 1:57 am

    Hi, simply wished to inform you, I enjoyed this article.

    It was excellent. Just continue uploading!

  10. HutchersonFebruary 26, 2013 ב 10:12 am

    This blog was… how do you say it? Relevant!! Finally I have found something
    which helped me. Thanks a lot!

  11. NielsonMarch 14, 2013 ב 2:38 pm

    Can I just say what a relief to find a person that really
    understands what they’re talking about on the web. You actually know how to bring a problem to light and make it important. More and more people ought to look at this and understand this side of the story. It’s surprising you’re not more popular since you surely possess the gift.

  12. GreenwoodMarch 22, 2013 ב 10:16 pm

    Link exchange is nothing else however it is simply placing the
    other person’s blog link on your page at appropriate place and other person will also do similar in support of you.

  13. MichaudMarch 22, 2013 ב 11:14 pm

    At this time I am going to do my breakfast, when having my breakfast
    coming over again to read more news.

  14. HofmannApril 20, 2013 ב 10:33 am

    Wonderful beat ! I wish to apprentice at the same time as you amend your site, how can i subscribe for
    a blog web site? The account aided me a acceptable deal.
    I have been tiny bit familiar of this your broadcast offered shiny clear concept

  15. SimpkinsApril 20, 2013 ב 3:20 pm

    Hola! I’ve been following your web site for a while now and finally got the courage to go ahead and give you a shout out from Houston Texas! Just wanted to mention keep up the fantastic job!

  16. garcinia cambogia videoApril 20, 2013 ב 3:31 pm

    rvouf8y, garcinia cambogia gnc garcinia cambogia pros cons ucpgd92taictynt8, 6288 funny likes for facebook funny things to like on facebook 1062 best seo company local online marketing company.

  17. how much is my car worth canada calculatorApril 20, 2013 ב 7:21 pm

    ippyrtk7jypv, 7704 debt consolidation [url=http://consolidate-debt.ca/]consolidation loans canada[/url] debt consolidation [url=http://www.yourcarvaluation.com]how much is my car worth red book[/url] 3194 value my car [url=http://www.quickcarvaluation.com]value my car malaysia[/url].

  18. payday advance kansas cityApril 21, 2013 ב 5:13 am

    [link=http://www.fasstcash.com]zip payday advance[/link] payday advance in pa [link=http://www.plumber24hrs.com/]plumber dublin oh[/link] t9ffvq9fh2tmoj, [link=http://www.fastcarvaluation.com]car valuation za[/link]

  19. kw how to get over a break up wikihowApril 21, 2013 ב 7:38 am

    eqfugjlzaa, personal student loans http://www.debtconsolidationreviews2013.com debt consolidation home consolidation loan 1eywptil5xvltz1, 3835 http://www.yelp.com/biz/yoga-bound-carlsbad Yoga Carlsbad lululemon yoga carlsbad ly8kwaxw0qjvja, http://www.youtube.com/watch?v=cfjFIJDBB2Y kw how to get over a break up quickly

  20. life insurance quote californiaApril 27, 2013 ב 8:07 pm

    vt7jnr, 4882 life insurance quotes missouri http://www.gzgefei.com/how-to-approach-long-term get insurance quote online rg4jwpx75zmzs1ta, http://trainingpaintlessdentremoval.com/citylinks/ paintless dent removal-trainingpaintlessdentremoval.com owmfewwx8ynu, 7602 http://rattan-furniture.org furniture jackson ms

  21. promo codes for fanduelMay 3, 2013 ב 5:59 pm

    5930 http://fanduelpromocode.webs.com/ fanduel promo code deposit bonus jdng9hcmwjjdtm, 2243 donald bernard giello http://www.huffingtonpost.com/2013/04/23/donald-bernard-mcgee-jr-a_n_3138976.html Donald Ray Bernard man6yv0jdw, https://www.youtube.com/watch?v=G46gvXdgukM Gaspari Superdrive Review Gaspari Superdrive.

  22. public liability insurance yoga teachersMay 8, 2013 ב 5:51 am

    o0uys982w, 2301 http://electroniccigaretteflavors.com/top-3-e-cigarette-reviews electronic cigarette miami electronic cigarette nicotine car insurance boston http://www.georgiacarinsurancequotes.org car insurance in georgia car insurance in georgia http://www.quickpublicliabilityinsurance.com public liability insurance definition.

  23. CatalanoMay 9, 2013 ב 2:13 am

    Horoscope leo astro.com gratuit

  24. small business web designMay 9, 2013 ב 8:24 pm

    n3zmjv6tp5k, satiereal saffron http://saffronextract4u.webs.com saffron rouge wjbrbrxc, 2542 http://vehiclesshipping.org car shipping zimbabwe vcrrocpgdfrjdu, 5982 http://www.smallbusinesswebdesign.co.uk web design london web design zurich

  25. WisniewskiMay 15, 2013 ב 7:31 pm

    Le tarot de marseille gratuit denis lapierre mon horoscope du jour belier

  26. sdksuys@gmail.comJuly 2, 2013 ב 11:10 pm

    These companies would rather spend their resources on creating an ad campaign than on creating a product that works well and keeps customers satisfied.