Ziv
Ziv

Reputation: 2785

How do I close a stream after a file transfer over WCF?

I am writing a web service that transfers a file over tcp using a binary, streaming connection.

I have some testing code set up but when I try to read the same file twice I get an exception, that the file is already open (by the previous call).

How can I close the file AFTER the transfer was complete? I tried a using block, but it didn't work.

Upvotes: 1

Views: 187

Answers (1)

Chris Shain
Chris Shain

Reputation: 51349

It's covered here: http://devdump.wordpress.com/2008/12/07/disposing-return-values/

Furthermore, you probably want to open the streams using a constructor like this one, as follows:

var myStream = new FileStream("blah.txt", FileMode.Read, FileAccess.Read);

That way, multiple clients can call your method simultaneously.

Upvotes: 2

Related Questions