Does WCF call a function without waiting for its completion?

On the client side, every time I call a function from my WCF service, it waits until the function completes in the WCF service, for example, it calls a local function. Therefore, I added an additional function for each of them, which launches the intended function in a new thread, so that almost all of my functions look like this:

EX:
I call the function from the CLIENT side of client.ReceiveFile() :

 private void SendFile(Socket socket, Job job, DoWorkEventArgs e) { UpdateInfo(job.Name, job.Icon, job.Size); client.ReceiveFile((_File)job.Argument, bufferSize); SizeAll = job.Size; UpdateCurrFile(((_File)job.Argument).Path, "1"); SendX(socket, ((_File)job.Argument).Path, e); } 

On the server, I have to do it as follows:

  public void ReceiveFile(_File file, int bufferSize) { System.Threading.Thread th = new System.Threading.Thread(unused => ReceiveFileTh(client, file.Name, file.Size, bufferSize)); th.Start(); } private void ReceiveFileTh(Socket client, string destPath, long size, int bufferSize) { try { ReceiveX(client, destPath, size, bufferSize); } finally { CloseClient(); } } 

The fact is that when I send File from the client, it tells the service to start receiving, but if I have not started a new thread, the client will wait until the service receives this file and send the data file.

Thus, WCF supports a method that does not make the client wait for the service function to complete! or will I have to use the above method?

+6
source share
2 answers

what you are looking for, [OperationContract(IsOneWay = true)] for more details see http://msdn.microsoft.com/en-us/magazine/cc163537.aspx

+15
source

The code generator for .NET.NET is built to support this โ€” you donโ€™t need to manually generate asynchronous versions of each method.

If you use Add Service Link in Visual Studio, check the dialog box at the top: check the "Create asynchronous operations" box. If you are using svcutil.exe , use the / async option to generate asynchronous client methods.

+1
source

Source: https://habr.com/ru/post/914190/


All Articles