WCF Streaming – slides and code

I held a presentation about WCF Streaming last Saturday, November 26th, at Microsoft HQ Bucharest. I illustrated WCF Streaming in a small client/server application which was supposed to (and in the end implemented it all) :

  • Show all files available on the server in the client application
  • Allow the end user to upload a file (up to 2GB) to the server
  • Allow the user to download a file from the server
  • Display a progress bar that would update in real-time showing the progress of the current transfer (upload or download)
  • Allow the user to press the “Stop” button to stop the current transfer (upload or download)

The code to achieve this in a simple (non-robust, not production quality etc.) manner is quite small : around 50 lines of code for the server and around 200 lines for the client. The WCF runtime takes care of the rest.

Points of interest (things for which I suffered and hopefully you won’t) :

  • Cassini (ASP.NET Web development) server does not support streaming, reports a cryptic (400 Bad request) error and it’s not documented at Microsoft!
  • It’s not enough at the server level to set the maxReceivedMessageSize at the binding element, you must also set it in the maxRequestLength attribute on the system.web/httpRuntime element if you host the service in a site.
  • Don’t try to define an operation with mixed types, that is, complex types that are decorated with MessageContract and any other types (including System.String). If one is MessageContract then all have to be. Found out the hard way, at runtime (not compile time)
  • In order to get the folder path for a WCF application you must use HostingEnvironment.GetApplicationPhysicalPath.
  • In .NET 4 there is a CopyTo method on the Stream class which simplifies copying data from a stream to another.
  • Opt in for asynchronous method generation for the client-side WCF proxies

You can find below the PowerPoint slides and the code archive attached to this post.

WCF Streaming – slides

WCF Streaming – the code

  1. Prezentare RONUA / ITCamp | Jurnal de programator - pingback on 1 December 2011 at 08:31
  2. CodeCamp and ITSpark autumn events | tudy .ro - Tudor Damian - pingback on 9 December 2011 at 10:38
  3. That is really superb. I spent almost 2 weeks in R&D for data transfer upto 1 GB via WCF Services. I want to consume this service in MVC 3.0 front end. Can you explain its consumption in MVC 3.0 asynchronously ?

  4. Multumesc mult pentru cod.
    Ma ajuta si am ce invata din el :-)
    O zi buna.

Leave a Comment


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

Trackbacks and Pingbacks:

WP Like Button Plugin by Free WordPress Templates