异步和并发WCF服务调用 [英] Asynchronous and Concurrent WCF service Calls

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

问题描述

你好,

我有一个WCF Web服务,该服务执行的功能可能需要10秒钟才能完成.

客户端可以通过通过线程池执行WCF调用或使用生成的异步方法来异步调用WCF Web服务.

但是,我想同时执行异步AS WELL功能,例如,对同一Web服务的许多调用彼此之间很快就会被调用.

因此,例如,wcf呼叫1在00:00发起
wcf呼叫2在00:01开始,然后在00:02呼叫3,依此类推.它们应该在00:10然后00:11和00:12完成.

在上面的例子中.该Web sservice被称为异步",但是顺序执行的,因此执行了调用1,延迟执行了10秒调用2,依此类推.

我更改了最大连接值,但无济于事.

我注意到,如果我将WCF服务功能创建为Web服务中的线程功能,则会达到预期的效果,即"wcf调用2在00:01启动,然后在00:02调用3,依此类推.它们应在以下时间完成00:10然后00:11和00:12.

但这真的是应该做的方式吗,是否有更整洁"的替代方法?

Hi there,

I have a WCF webservice that executes a function that could take around 10 seconds to complete.

The client can call the WCF web service asynchronously by either executing the WCF calls via a thread pool, or using the generated asynchronous methods.

However I would like to execute the functions async AS WELL as concurrently, ie many calls to the same web service to be called very shortly after each other.

So for example wcf call 1 is initiated at 00:00
wcf call 2 is initiated at 00:01, then call 3 at 00:02 etc. They should complete at 00:10 then 00:11 and 00:12.

In the above examples. The web sservice is called asynch but executed sequentially, so call 1 is executed, 10 seconds late call 2 is executed and so forth.

I have change the max connection values, but to no avail.

I notice that if I create the WCF service function as a threaded function within the web service, i get the desired effect, ie "wcf call 2 is initiated at 00:01, then call 3 at 00:02 etc. They should complete at 00:10 then 00:11 and 00:12".

But is this really the way it should be done, is there any alternatives, that are "neater"?

推荐答案

我的看法是:所有异步调用都很好地控制了线程没有介绍或没有建立.我看不到什么情况可以击败线程.线程更容易实现,因为在单个线程中所有逻辑都是顺序的,它们配备了线程同步原语,最终可以更正确地使用它们.

线程创建的相对昂贵的操作可以通过使用线程池来补偿,或者更好的是通过使用永久线程"(具有与整个过程的生命周期几乎相同的生命周期的线程)来补偿,该永久线程"被线程同步限制并重新用于重复任务.

我通过阻止消息队列提供了一种非常常规的限制方式.请参阅我的提示/技巧文章:用于线程通信和内部交互的简单阻塞队列线程调用 [ ^ ].

请看一下我过去在此主题和相关主题上的解决方案:
如何获取keydown事件在vb.net中的不同线程上操作 [启用禁用+多线程后控件事件不会触发 [ ^ ].

—SA
My opinion is: all asynchronous calls dominated well threading was not introduced or well established. I don''t see situation when those could beat threads. Threads are easier to implement as in a single thread all logic is sequential, they are well equipped with thread synchronization primitives and are ultimately more reliable is used properly.

The relatively costly operation of thread creation could be compensated by using thread pools or, better yet, by using "permanent threads" (threads with life time nearly the same of that of the whole process) throttled by thread synchronization and reused for repeated task.

I offer a very regular way of such throttling via a blocking message queue; see my Tips/Trick article: Simple Blocking Queue for Thread Communication and Inter-thread Invocation[^].

Please take a look at my past solutions on this and related topics:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA


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

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