0

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

InnaZis
  • 79
  • 1
  • 2
  • 14

3 Answers3

7

You can check this tutorials for .net 4.5:

http://www.codeproject.com/Articles/613678/Task-based-Asynchronous-Operation-in-WCF

http://www.codeguru.com/columns/experts/building-and-consuming-async-wcf-services-in-.net-framework-4.5.htm

http://jaliyaudagedara.blogspot.com/2013/03/asynchronous-operations-in-wcf.html

and the same qa:

Pattern for calling WCF service using async/await

good example:

https://github.com/BradRem/CslaAsyncWcfService

https://github.com/tomfaber/asyncdemo

https://github.com/kekekeks/AsyncRpc

https://github.com/devcurry/async-await-in-wcf

Update

for .net 4.0:

msdn.microsoft.com/en-us/library/ms731177(v=vs.100).aspx

it's old pattern but good for .net 4.0

msdn.microsoft.com/en-us/library/ms228963(v=vs.100).aspx
codeproject.com/Articles/14898/Asynchronous-design-patterns

example: github.com/mikehadlow/Mike.AsyncWcf

Community
  • 1
  • 1
AndreyMaybe
  • 309
  • 1
  • 2
  • 8
  • Thanks, tutorials are good. The only problem - my service uses a Framework 4.0 and there is no async component. I tried this one but it didn't work either: http://www.koodr.com/snippet/96bb649d/an-example-multi-threaded-web-service-calls-in-asp-net-using-system-threading-tasks-parallel-foreach-parallelprogramming – InnaZis Dec 07 '13 at 18:35
  • for .net 4.0 you can use: http://msdn.microsoft.com/en-us/library/ms731177(v=vs.100).aspx – AndreyMaybe Dec 08 '13 at 22:08
  • it's old pattern but good for .net 4.0 http://msdn.microsoft.com/en-us/library/ms228963(v=vs.100).aspx – AndreyMaybe Dec 08 '13 at 22:18
1

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.

Stephen Cleary
  • 437,863
  • 77
  • 675
  • 810
0

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);
Zoe
  • 27,060
  • 21
  • 118
  • 148