Click here to Skip to main content
15,885,365 members
Articles / WCF

WCF Streaming – Slides and Code

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
21 Aug 2012CPOL2 min read 17.9K   597   7   12
The PowerPoint slides and code for my presentation on WCF streaming

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 by 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 the PowerPoint slides and the code archive attached to this post.


This article was originally posted at http://blog.andrei.rinea.ro/2011/11/26/wcf-streaming

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) IBM, Business Analytics
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionCancelling file download Pin
Boris 00714-Nov-12 0:37
Boris 00714-Nov-12 0:37 
AnswerRe: Cancelling file download Pin
Andrei Ion Rînea14-Nov-12 3:30
Andrei Ion Rînea14-Nov-12 3:30 
GeneralRe: Cancelling file download Pin
jonasgranlund29-Jul-13 4:07
jonasgranlund29-Jul-13 4:07 
QuestionNice work Pin
Stephen Asher15-Oct-12 1:25
Stephen Asher15-Oct-12 1:25 
AnswerRe: Nice work Pin
Andrei Ion Rînea15-Oct-12 3:35
Andrei Ion Rînea15-Oct-12 3:35 
GeneralMy vote of 5 Pin
Christian Amado21-Aug-12 5:39
professionalChristian Amado21-Aug-12 5:39 
GeneralRe: My vote of 5 Pin
Andrei Ion Rînea22-Aug-12 2:36
Andrei Ion Rînea22-Aug-12 2:36 
QuestionSo you just wrapped Stream ? Pin
Jasper4C#21-Aug-12 1:32
Jasper4C#21-Aug-12 1:32 
AnswerRe: So you just wrapped Stream ? Pin
Andrei Ion Rînea21-Aug-12 3:17
Andrei Ion Rînea21-Aug-12 3:17 
QuestionWWE translation? Pin
BigTimber@home20-Aug-12 8:09
professionalBigTimber@home20-Aug-12 8:09 
Do you have an English translation of the slides?
AnswerRe: WWE translation? Pin
Andrei Ion Rînea21-Aug-12 1:34
Andrei Ion Rînea21-Aug-12 1:34 
AnswerSlides translation available now :) Pin
Andrei Ion Rînea21-Aug-12 3:14
Andrei Ion Rînea21-Aug-12 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.