DCSIMG
What’s new in WCF 4.5? Improved streaming in IIS hosting - Ido Flatow's Blog Veni Vidi Scripsi

Ido Flatow's Blog

Veni Vidi Scripsi

News

Have you heard me speak?
Powered
<style type='text/css' media='screen' id='sm_css'> #smix {overflow: visible;height: auto;border-radius: 10px;max-width: 250px;background-color: #323232;text-align: left;font-size: 12px;line-height: 16px;font-family:'Lucida Sans Unicode','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;-webkit-border-radius: 10px;-moz-border-radius: 10px;border-radius: 10px;} #smix a {color: #0056CC;text-decoration: none;} #smix .sm_head {color: #fff; line-height: 1em;font-size: 1.4em;padding: 10px;color: #fff;} #smix .sm_lanyard_wrapper {background-color: #fff;;clear: both;width: 97%;margin: 0 auto;margin-bottom: 0px;} #smix .sm_lanyard_content {padding: 7px;}#smix button.sm_rec, #smix a.sm_rec, #smix input[type=submit].sm_rec { padding: 6px 10px; -webkit-border-radius: 2px 2px;-moz-border-radius: 2px; border-radius: 2px; border: solid 1px rgb(153, 153, 153); background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(255, 255, 255)), to(rgb(221, 221, 221))); color: #333; text-decoration: none; cursor: pointer; display: inline-block; text-align: center; text-shadow: 0px 1px 1px rgba(255,255,255,1); line-height: 1; }#smix .sm_rec:hover { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(248, 248, 248)), to(rgb(221, 221, 221))); }#smix .sm_rec:active { background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(204, 204, 204)), to(rgb(221, 221, 221))); }#smix .sm_rec.medium { padding: 3px 7px; font-size: 13px; }#smix .sm_rec span.icon.thumbs_up {background-position: 0px 36px;vertical-align: text-top;display: inline-block;margin-right: 4px;height: 18px;width: 16px;background-image: url(http://speakermix.com/images/new/thumbsold.png);}#smix .sm_rec:hover span.icon.thumbs_up {background-position: 0px 18px;} #smix .sm_events {padding:2px 0px 4px 0px;} #smix .sm_section {font-size: 10px; border-bottom: 1px solid silver; margin-bottom: 6px;} #smix .sm_subline {font-size:120%;margin-top:4px;font-weight:bold} #smix .powered {text-align: right} #smix .powered img {margin: 7px} </style>
Sela Technology Center

Advertisement

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

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:

image

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.

Comments

The Morning Brew - Chris Alcock » The Morning Brew #1025 said:

Pingback from  The Morning Brew - Chris Alcock  &raquo; The Morning Brew #1025

# January 19, 2012 11:34 AM

James Manning said:

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

# January 19, 2012 4:48 PM

Distributed Weekly 138 — Scott Banwart's Blog said:

Pingback from  Distributed Weekly 138  &mdash;  Scott Banwart&#039;s Blog

# January 20, 2012 3:02 PM

What's new in WCF 4.5? Improved streaming in IIS hosting – Ido … | Hosting said:

Pingback from  What&#039;s new in WCF 4.5? Improved streaming in IIS hosting &#8211; Ido &#8230; | Hosting

# January 21, 2012 2:34 PM

What???s new in WCF 4.5? Improved streaming in... | Web Services | Syngu said:

Pingback from  What???s new in WCF 4.5? Improved streaming in... | Web Services | Syngu

# January 22, 2012 8:51 AM

Konstantin said:

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

# January 27, 2012 6:41 PM

Ido Flatow said:

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.

# January 28, 2012 8:48 PM

Ido Flatow said:

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.

# January 28, 2012 8:50 PM

Daniel said:

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.

# July 21, 2012 8:58 PM

Fleck said:

Good way of describing, and good article to take information about my presentation focus, which i

am going to deliver in college.

# September 19, 2012 9:44 PM

Singleton said:

Thanks for sharing your thoughts on Ido Flatow

WCF MOC HPC Azure Entity Framework Silvelright.

Regards

# December 10, 2012 6:55 PM

Weed said:

Hello, this weekend is good for me, because

this time i am reading this fantastic educational

post here at my house.

# December 16, 2012 11:36 AM

Scroggins said:

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

It was excellent. Just continue uploading!

# January 17, 2013 1:57 AM

Hutcherson said:

This blog was... how do you say it? Relevant!! Finally I have found something

which helped me. Thanks a lot!

# February 26, 2013 10:12 AM

Nielson said:

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.

# March 14, 2013 2:38 PM

Greenwood said:

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.

# March 22, 2013 10:16 PM

Michaud said:

At this time I am going to do my breakfast, when having my breakfast

coming over again to read more news.

# March 22, 2013 11:14 PM

Hofmann said:

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

# April 20, 2013 10:33 AM

Simpkins said:

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!

# April 20, 2013 3:20 PM

garcinia cambogia video said:

rvouf8y, <a href="garciniacambogiaextractslim.com/">garcinia cambogia gnc</a> garcinia cambogia pros cons ucpgd92taictynt8,  6288 <a href="http://swagsocials.com">funny likes for facebook</a> funny things to like on facebook  1062 best seo company <a href="http://topseopicks.com">local online marketing company</a>.

# April 20, 2013 3:31 PM

how much is my car worth canada calculator said:

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

# April 20, 2013 7:21 PM

payday advance kansas city said:

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

# April 21, 2013 5:13 AM

kw how to get over a break up wikihow said:

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

# April 21, 2013 7:38 AM

life insurance quote california said:

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

# April 27, 2013 8:07 PM

promo codes for fanduel said:

5930 fanduelpromocode.webs.com fanduel promo code deposit bonus jdng9hcmwjjdtm,  2243 donald bernard giello www.huffingtonpost.com/.../donald-bernard-mcgee-jr-a_n_3138976.html Donald Ray Bernard man6yv0jdw, www.youtube.com/watch Gaspari Superdrive Review Gaspari Superdrive.

# May 3, 2013 5:59 PM

public liability insurance yoga teachers said:

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

# May 8, 2013 5:51 AM

Catalano said:

Horoscope leo astro.com gratuit

# May 9, 2013 2:13 AM

swimsuits for women said:

www.protein-shakes-diet.co.uk protein shakes good adobephotoshopfreedownload2013.webs.com photoshop mask photoshop cs2 jwy4aof,  5946 http://www.nwtpa.com bathing suits bathing suits.

# May 9, 2013 3:27 AM

small business web design said:

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

# May 9, 2013 8:24 PM

Wisniewski said:

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

# May 15, 2013 7:31 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: