Send file name in streaming transfer mode
I want to send a file using WCF in streaming transfer mode. At the server side I have t开发者_C百科he following code.
public void LoadPicture(Stream stream)
{
FileStream file = new FileStream(GetAbsolutePath("asdf.jpg"), FileMode.CreateNew);
byte[] buffer = new byte[bufferSize];
int countRead;
while ((countRead = stream.Read(buffer, 0, bufferSize)) > 0)
{
file.Write(buffer,0, countRead);
}
file.Close();
}
But I want to send a recomended fileName (or some additional information) somehow. How can it be done? Thanks in advance.
In streaming mode, WCF can only send the stream itself in the message body, as you discovered. The trick to get around the problem is to use a MessageContract so you can add extra details in the header (like a suggested file name).
This question (and the MSDN link contained in it) should help: WCF: using streaming with Message Contracts
精彩评论