当关闭WCF客户端? [英] When to close WCF client?

查看:137
本文介绍了当关闭WCF客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把对WCF服务的客户端代理的一个实例到在App类的属性,所以我可以在该应用的任何得到它。

I've put an instance of the client proxy for the WCF service into a property on the App class so I can get it from anywhere in the app.

我不关闭客户端,我要离开它打开应用程序的持续时间。造成这种情况的主要原因是,如果我是按照WCF服务MEX页面(如果你点的WCF服务URL的浏览器你得到的)它说,//注释//始终关闭客户端。
client.Close();

I am not closing the client, I'm leaving it open for the duration of the app. The main reason for this is that if I were to follow the // Comment in the WCF service mex page (the one you get if you point a browser at the WCF service url) it says // Always close the client. client.Close();

这是很好的,但如果我叫client.Close()我做出client.SomeAsync一个电话后立即()方法,那么结果回来之前,它被关闭。我应该把靠近入完成()方法?或者我应该忘记关闭它,因为一旦其关闭我要创建客户端代理的新实例(还不如不将其存储在App.property如果是这样的情况。

which is fine, except if I call client.Close() right after I make a call to client.SomeAsync() method then it's being closed before the results come back. Should I be putting the close into the Completed() method? Or should I just forget about closing it, as once its closed I have to create a new instance of the client proxy (might as well not store it in the App.property if that is the case.

感谢,
斯蒂芬

thanks, Stephen

推荐答案

您应该关闭它的建议。是的,如果您正在使用的异步方法,那么你必须关闭它在调用完成后只。

You should close it as advised. And yes, if you're using the async methods then you have to close it only after the call completes.

创建(打开)和关闭客户端是WCF客户端的标准。有没有明显的性能损失不断创建和关闭新的客户。

Creating (opening) and closing clients is the norm for WCF clients. There is no noticeable performance penalty for continuously creating and closing new clients.

这篇关于当关闭WCF客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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