WCF同步和异步调用的区别? [英] Difference between WCF sync and async call?

查看:35
本文介绍了WCF同步和异步调用的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 WCF 的新手,想知道它使同步调用或异步调用有什么区别,如果有人能用例子解释一下会很有帮助

I am new to WCF, want to know what difference it make sync call or async call, it will be really helpful if some one will explain with example

谢谢

推荐答案

来自客户端的异步调用与 .NET Framework 中的任何其他异步操作相同.当您从一个线程对 WCF 服务进行同步调用时,该线程将挂起.这意味着在服务调用返回响应或异常之前,线程将无法执行任何其他工作.相比之下,异步调用将在单独的线程(由框架创建)中运行,因此您的主线程将能够继续运行,并且将通过回调(事件)通知异步调用完成.

Async call from the client is same as any ohter async operation in .NET Framework. When you make sync call from a thread to the WCF service the thread will hang on. It means thread will not be able to do any other work until the service call returns response or exception. In contrast the async call will run in separate thread (created by framework) so your main thread will be able to continue in operation and it will be notified about completion of async call by callback (event).

假设您有 WinForms 应用程序作为 WCF 客户端,并且您想调用 WCF 服务.如果您进行同步调用需要几秒钟才能完成,您的应用程序将在此处理时间内挂起 = 用户将无法对应用程序执行任何操作(只能从任务管理器中删除它).但是如果您使用异步调用,它将是完全交互的,因为异步操作将由后台线程处理.因此异步操作适用于交互式解决方案,或者如果您需要并行执行多个操作.

So suppose that you have WinForms application as WCF client and you want to call WCF service. If you make a sync call which will take several seconds to complete your application will hangs on for this processing time = user will not be able to do anything with application (only kill it from task manager). But if you use async call it will be fully interactive because async operation will be handled by background thread. So async operations are suitable for interactive solutions or if you need to do multiple operations in parallel.

例如,查看 MSDN 中的 How to article.

For example check this How to article from MSDN.

为了完整起见,我描述了同步和异步调用之间的区别 = 客户端上的同步和异步处理.WCF 还支持同步和异步操作 = 服务器上的同步和异步处理.

Just for completness I described difference between sync and async calls = synchronous and asynchronous processing on the client. WCF also supports sync and async operations = synchronnous and asynchronous processing on the server.

这篇关于WCF同步和异步调用的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆