WCF Chunking / Streaming

I'm using WCF and want to upload a large file from the client to the server. I have investigated and decided to follow the chunking approach outlined at http://msdn.microsoft.com/en-us/library/aa717050.aspx

However, this approach (just like streaming) restricts the contract to limited method signitures:

void UploadStream(Stream stream);

The sample uses the rather convenient example of uploading a file from a fixed path and saving it to a fixed path on the server. Therefore, my question is how do I pass additional parameters to specify things like filename, filepath etc.

eg. I would like something like:

void UploadStream(Stream stream, String filePath);

Thanks in advance, Mark.


This article explains how to use the MessageHeader attribute to force things to be passed in the header, and therefore not count as a parameter. So, instead of passing a stream and other meta data, create a class that has the attribute MessageContract and mark all of the meta data as a MessageHeader. Then, mark the stream as a MessageBodyMember (which the article incorrect calls "MessageBody"). Have your UploadStream method take a single parameter whose type is that of the MessageContract class you've just created. I've done this successfully, but I haven't done it in tandem with chunking. Good luck.

You could make your service session-ful and have an initialization method in the contract with the IsInitiating property set to true. Something like:

[OperationContract(IsInitiating = true)]
void InitializeUploadService(string filename);

[OperationContract(IsOneWay = true, IsInitiating = false)]
void UploadStream(Stream stream);

I have never tried it with streaming services but it should basically make WCF enforce that InitializeUploadService is always called before UploadStream.

More documentation can be found here: http://msdn.microsoft.com/en-us/library/system.servicemodel.description.operationdescription.isinitiating.aspx

I would look at MessageContracts and add those values as message headers to your object. This should allow you to pass the stream and any values related to the stream as message headers.

Setting up the maxItemsInObjectGraph in the Client side and Server side worked for me.

(Dont forget the client side.) http://social.msdn.microsoft.com/Forums/en/wcf/thread/0af69654-2d89-44f3-857a-583b57844ca5

Need Your Help

Google Contacts read only (OAuth 2.0)

oauth gmail contacts

We're using OAuth 2.0 to access Gmail Contacts. Do you know if it is possible to request access (scope) in such a way that the authorization pop-up indicates that we need read only access.

Why is my DLookup producing "invalid use of null" Error: 94

sql excel vba ms-access access-vba

In my Access VBA code, I have several DLOOKUP functions in a sequence. They are all the same except for the value the parameter they are returning from 'studys'.