[英]Simple async task example for an WCF Service in C#
I'm writing a WCF service for an android application. 我正在为Android应用程序编写WCF服务。 The flow is pretty simple: 流程非常简单:
I suppose it has to be something with async task and threads that I never used in C#. 我想它一定是带有异步任务和线程的东西,而我在C#中从未使用过。 Searching for a simple example I lost in sophisticated tutorials and rich opportunities what could be done with tasks and threads in C#. 在寻找一个简单的示例时,我在复杂的教程中失去了很多机会,而在C#中使用任务和线程可以完成很多工作。 What is the best practice in this case? 在这种情况下,最佳做法是什么? The very simple example would be very appreciated. 非常简单的示例将不胜感激。
UPD. UPD。 The service uses a Framework 4.0 该服务使用Framework 4.0
You can check this tutorials for .net 4.5: 您可以查看.net 4.5的本教程:
http://www.codeproject.com/Articles/613678/Task-based-Asynchronous-Operation-in-WCF 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://www.codeguru.com/columns/experts/building-and-using-async-wcf-services-in-.net-framework-4.5.htm
http://jaliyaudagedara.blogspot.com/2013/03/asynchronous-operations-in-wcf.html http://jaliyaudagedara.blogspot.com/2013/03/asynchronous-operations-in-wcf.html
and the same qa: 和相同的质量检查:
Pattern for calling WCF service using async/await 使用async / await调用WCF服务的模式
good example: 好例子:
https://github.com/BradRem/CslaAsyncWcfService https://github.com/BradRem/CslaAsyncWcfService
https://github.com/tomfaber/asyncdemo https://github.com/tomfaber/asyncdemo
https://github.com/kekekeks/AsyncRpc https://github.com/kekekeks/AsyncRpc
https://github.com/devcurry/async-await-in-wcf https://github.com/devcurry/async-await-in-wcf
Update 更新资料
for .net 4.0: 对于.net 4.0:
msdn.microsoft.com/en-us/library/ms731177(v=vs.100).aspx msdn.microsoft.com/zh-CN/library/ms731177(v=vs.100).aspx
it's old pattern but good for .net 4.0 这是旧模式,但适用于.net 4.0
msdn.microsoft.com/en-us/library/ms228963(v=vs.100).aspx msdn.microsoft.com/zh-CN/library/ms228963(v=vs.100).aspx
codeproject.com/Articles/14898/Asynchronous-design-patterns codeproject.com/Articles/14898/Asynchronous-design-patterns
example: github.com/mikehadlow/Mike.AsyncWcf 示例: github.com/mikehadlow/Mike.AsyncWcf
This doesn't have anything to do with async
. 这与async
没有任何关系。
The proper solution requires a reliable queue (eg, an Azure queue) and an independent backend (eg, an Azure worker role). 正确的解决方案需要可靠的队列(例如,Azure队列)和独立的后端(例如,Azure工作人员角色)。 When your app initially sends data to the WCF app, it should place it in the queue and return the result. 当您的应用程序最初将数据发送到WCF应用程序时,应将其放在队列中并返回结果。 The independent background worker then reads from the queue and does the actual processing. 然后,独立的后台工作人员从队列中读取并进行实际处理。
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/ https://developwar.wordpress.com/2019/01/14/real-problem-asynchronous-programming-with-wcf-services-or-any-web-service-in-net/
ie 即
wcfObject objectFromService = await serviceClient.GetObjectByIDAsync(idParameter).ConfigureAwait(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.