一遍又一遍地使用客户端与每个呼叫创建一个新客户端 [英] Using client over and over vs creating a new one per call

查看:62
本文介绍了一遍又一遍地使用客户端与每个呼叫创建一个新客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在开发一个使用一些肥皂服务来获取数据的股市应用程序.对该服务的呼叫非常频繁,例如每秒最多10个呼叫.

I am developing a stock market app which uses some soap services to get data. Calls to the services are quite frequent, up to 10 calls per second for example.

 

当我进行这些调用时,我应该尝试一遍又一遍地重用同一客户端对象,还是为每个调用创建一个新的客户端对象?问题是,如果我从同一个客户端发出异步请求...我可能无法使用客户端对象的Abort方法,因为 当时可能有几个待处理的响应.如果我为每个呼叫都使用新客户端,这将不是问题,但对我来说似乎有点开销.您的想法?

When i make these calls, should i try to reuse the same client object over and over again, or create a new one for each call? The thing is, if i make async requests from the same client... i probably cant use the Abort method of the client object, because there may be several responses pending at the time. This wouldnt be a problem if i used  new client for every call, but it seems a bit like overhead to me. Your thoughts?

推荐答案

您好,两者都很好.当您频繁调用服务时,使用单个客户端可能会给您带来更好的性能,尤其是在使用TCP的情况下. TCP绑定使您可以重用相同的TCP连接. HTTP绑定仍然需要新的连接 对于每个服务调用,但可能会节省一些CPU周期,以便在客户端上重新创建WCF对象.但是,如果您需要将连接idel保留一会儿,建议关闭它以释放资源.此外,如果出现问题, 您必须创建一个新的客户端对象.
Hello, both are fine. Using a single client may give you a bit better performance when you call the service frequently, especially if you use TCP. TCP binding allows you to reuse the same TCP connection. HTTP binding still requires a new connection for each service call, but may save you a bit CPU cycles to recreate the WCF objects on the client. If you need to leave the connection idel for a while, however, it is recommended to close it to free resources. In addition, if something goes wrong, you must create a new client object.


这篇关于一遍又一遍地使用客户端与每个呼叫创建一个新客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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