First of all, it is not difficult to copy the file through WCF.
The problem is to get the percentage, and my method can be viewed in real-time in the WCF console.
Server:
Service1:
public void CopyFile(string source, string target, ref float percent, int bufferSize = 1024 * 1024 * 10)
{
byte[] array = new byte[bufferSize];
using (FileStream fsRead = File.Open(source, FileMode.Open, FileAccess.Read))
{
using (FileStream fsWrite = File.Open(target, FileMode.Create, FileAccess.Write))
{
while (fsRead.Position < fsRead.Length)
{
int length = fsRead.Read(array, 0, array.Length);
fsWrite.Write(array, 0, length);
percent = (float)fsRead.Position / fsRead.Length;
Console.WriteLine(percent.ToString());
}
}
}
}
IService1:
[OperationContract]
void CopyFile(string source, string target, ref float percent, int bufferSize = 1024 * 1024 * 10);
Client:
Service1Client client=new Service1Client();
float percent = 0;
string source = @"xxxx";
string target = @"xxxx";
percent=client.CopyFile(source, target,ref percent,1024*1024*10);
My suggestion would be to put this code directly in your WPF project. This will allow you to replace the Console.Write line with the display data.
App.config
(WCF & Windows Service) I setup<bindings>
with net pipe endpoint and it works. In WCF I've created aMyService.cs
andIMyService.cs
- it allows me to call WCF methods from GUI(in GUI I prepared classServiceClient
withChannelFactory
) and methods. If I'm wrong please correct me if you know how to handle that type of communication...