WCF 服务代理生命周期的最佳实践? [英] Best Practice for WCF Service Proxy lifetime?

查看:48
本文介绍了WCF 服务代理生命周期的最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 WCF 服务时,每次使用它时都创建一个新的服务实例是否更好?还是创建一个并重新使用它更好?为什么两种方法都更好?异步代理是一样的吗?

When working with WCF services, is it better to create a new instance of the service every time you use it? Or is it better to create one and re-use it? Why is either approach better? Is it the same for asynchronous proxies?

推荐答案

除了 Guy Starbuck 提到的一个关键因素是您使用的安全模型(结合会话要求) - 如果您不这样做'如果不重复使用您的代理,就不能重复使用安全会话.

in addition to the things Guy Starbuck mentioned a key factor would be the security model you're using (in conjunction with the session requirements) - if you don't re-use your proxy, you can't re-use a security sessions.

这意味着客户端必须在每次调用时都进行身份验证,这很浪费.

This means that the client would have to authenticate itself with each call which is wasteful.

但是,如果您决定这是您想要做的,请确保将客户端配置为不建立安全上下文(因为您永远不会使用它),这将为您节省几次往返服务器的时间:-)

If, however, you decide this is what you wish to do, make sure to configure the client to not establish a security context (as you will never use it), this will save you a couple of roundtrips to the server :-)

这篇关于WCF 服务代理生命周期的最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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