C#中WCF服务的简单异步任务示例 [英] Simple async task example for an WCF Service in C#
问题描述
我正在为Android应用程序编写WCF服务.流程非常简单:
I'm writing a WCF service for an android application. The flow is pretty simple:
- 应用程序将数据发送到方法.
- 该方法返回一个结果,指示它已获取数据.
- 我必须继续处理数据,而不必等待任何结果,应用程序需要获得响应,然后才能对这些数据进行任何处理.
我想它一定是带有异步任务和线程的东西,而我从未在C#中使用过.在寻找一个简单的示例时,我在复杂的教程中失去了很多机会,而在C#中使用任务和线程可以完成很多工作.在这种情况下,最佳做法是什么?非常简单的示例将不胜感激.
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.该服务使用Framework 4.0
UPD. The service uses a Framework 4.0
推荐答案
您可以在.net 4.5中查看此教程:
You can check this tutorials for .net 4.5:
http://www.codeproject.com/Articles/613678/WCF中基于任务的异步操作
http://jaliyaudagedara.blogspot.com/2013/03/asynchronous-operations-in-wcf.html
和相同的质量检查:
很好的例子:
https://github.com/BradRem/CslaAsyncWcfService
https://github.com/tomfaber/asyncdemo
https://github.com/kekekeks/AsyncRpc
https://github.com/devcurry/async-await-in-wcf
更新
.net 4.0:
msdn.microsoft.com/en-us/library/ms731177(v = vs.100).aspx
这是旧模式,但适用于.net 4.0
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
示例: github.com/mikehadlow/Mike.AsyncWcf
这篇关于C#中WCF服务的简单异步任务示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!