InnaZis
InnaZis

Reputation: 89

Simple async task example for an WCF Service in C#

I'm writing a WCF service for an android application. The flow is pretty simple:

  1. The app sends a data to the method.
  2. The method returns back a result indicating that it got the data.
  3. I have to proceed the data further without waiting for any result, the app needs to get a response before I make anything with this data.

I suppose it has to be something with async task and threads that I never used in C#. Searching for a simple example I lost in sophisticated tutorials and rich opportunities what could be done with tasks and threads in C#. What is the best practice in this case? The very simple example would be very appreciated.

UPD. The service uses a Framework 4.0

Upvotes: 0

Views: 22673

Answers (3)

Carlos Andres
Carlos Andres

Reputation: 63

I just found something simplified here.

https://developwar.wordpress.com/2019/01/14/real-problem-asynchronous-programming-with-wcf-services-or-any-web-service-in-net/

i.e.

wcfObject objectFromService = await serviceClient.GetObjectByIDAsync(idParameter).ConfigureAwait(false);

Upvotes: 1

Stephen Cleary
Stephen Cleary

Reputation: 456322

This doesn't have anything to do with async.

The proper solution requires a reliable queue (e.g., an Azure queue) and an independent backend (e.g., an Azure worker role). When your app initially sends data to the WCF app, it should place it in the queue and return the result. The independent background worker then reads from the queue and does the actual processing.

Upvotes: 1

Related Questions