tags:

views:

53

answers:

2

Hi, I am building a digital signage application and i need to allow my users to upload large images/videos. I have looked at the streaming mode to allow upload and download of the file, which seems to be the way to go. My problem is though that i need to figure out the proper approach to uploading. I need to put an entry into my database, then upload the file to a specific folder on the server (each customer has his own folder, whre the file needs to be placed). My problem is that it doesnt seem possible to send more information along with the file, than the stream to upload. All i need is some metadata, name of file and customer id. Anyone has a working example of this or point me in the right direction...

Sincerely /Brian

+1  A: 

Well, you're not saying what you've tried and how it failed, but here's a basic outline of how we're doing it:

[ServiceContract]
public interface IMyStreamingService
{
    [OperationContract]
    void Upload(FileUploadRequest request);
}

[MessageContract]
public class FileUploadRequest
{
    [MessageHeader(MustUnderstand = true)]
    public string Path;

    [MessageBodyMember(Order = 1)]
    public Stream FileData;

    public FileUploadRequest(string path, Stream fileData)
    {
        this.Path = path;
        this.FileData = fileData;
    }
}
500 - Internal Server Error
Your message contract does not define what is message header and what is message body - the most important part of the whole trick.
Ladislav Mrnka
I tried this approach, since its in the ms samples. i get an exception though since the composite object (fileuploadrequest) contains a stream and i assign it with File.OpenRead(mypath), and FileStream is not serializable.
H4mm3rHead
As Ladislav points out, I left out a couple of important attributes. I've added them to the example above.
500 - Internal Server Error
Is this approach possible for both basicHttp and tcp endpoints, right now im trying with basicHttp, but keep getting the exception that it cannot serialize my FileStream. Any experiences on that?
H4mm3rHead
Yes, we use this approach with both tcp and http.
500 - Internal Server Error
A: 

I have answered similar question few days ago. You have to declare operation which accepts and returns message contracts. You have to create message contracts. For streaming contract can contain only single body member which is of type Stream. Other contract members must to be declared as headers. Linked question contains full example for downloading. You just need to do the same for uploading.

Ladislav Mrnka