I uses netTcpBinding and streaming to send files from one server to another like described in this codeproject article,as I understand In wcf when we want to send stream we should create and return it as message contract, the question is how to get the finish of file sending? cause I want to move file from inbox to outbox when file sent guarantee completed
How to delete file after end of streaming wcf
Asked Answered
I found great solution in this blog if someone will need it in the future
OperationContext clientContext = OperationContext.Current;
clientContext.OperationCompleted += new EventHandler(delegate(object sender, EventArgs args)
{
if (fileStream != null)
fileStream.Dispose();
});
This was the solution I can across and did seem great at first. However, it executes whether the client has successfully copied the stream or not. This isn't a problem if you're just trying to dispose resources (in fact, it's perfect for that). But it is a problem if you're moving the file or, worse, deleting it. –
Japhetic
Yea you are right @Jeff, I found deffect latter, did you know another way to do that? –
Erin
When the second server has finished receiving the file from the first server, it could then call another web service method to acknowledge that it got the file. At that point, you can move the file from inbox to outbox with a guarantee that the other server received it.
Good, but what if the first server get the file, and lost the connection when trying to ask for moving to inbox? than the client will receive file twice –
Erin
You are correct, when designing a reliable distributed system, you need to account for all types of scenarios where messages are lost, servers go down, etc. You will have to come up with a design that handles this situation and makes sure not to create duplicate files. I don't believe there is anything in WCF that will help you do this automatically. –
Reliant
I guess I found solution, check my answer –
Erin
© 2022 - 2024 — McMap. All rights reserved.