wcf 操作上下文 [英] wcf operationContext

查看:24
本文介绍了wcf 操作上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有一个桌面应用程序,它与我也在构建的 wcf 服务进行通信

hello i have a desktop application that communicate with a wcf service that i building as well

我希望能够在没有数据库(有状态服务器)的情况下管理服务器内的登录用户

i want to be able to manage the logged on users inside the server without a db (statefull server)

我还希望服务器知道如何处理来自同一台计算机的 2 个客户端,最简单的方法是什么?

i also want the server to know how to handle 2 client from same computer, whats the simplest way of doing it?

我也有超过 1 个服务供客户使用(登录服务和应用服务)

i also have more than 1 service that the client work with (login service and app service)

是否有任何 operationContext 属性可以帮助我?

is there any operationContext Property that can help me?

推荐答案

您可以明确地管理服务器内的登录用户.我创建了一个个人模式来处理这种情况,通常是这样的:

You can deffinetly manage the logged users inside the server. I have created a personal pattern for dealing with such situations, and it ussually goes like this:

  • 在 WCF 服务器内创建一个客户端类,该类将保存有关客户端的所有所需信息.
  • 在服务中创建2个方法:logIn、logOut.login 方法应该能够收集有关您要存储的客户端的所有信息.确保定义可以唯一标识客户端实例的属性.当客户端连接到服务器时,它调用登录方法,允许服务器收集和保存来自客户端的信息.如果使用回调,这是在客户端 obejt 中保存 CallBack 上下文对象的地方.您现在可以将 Client 对象保存在 WCF 服务器实例中(我使用字典).当客户端注销时,它调用注销方法,服务器删除该条目.
  • 在服务器中创建一个 KeepAlive 方法,定期检查连接的客户端以查看它们是否仍然连接(如果网络故障或应用程序崩溃,客户端可能不会调用注销方法).

我认为这是在服务器中管理客户端的最简单的方法(并不是说它是最好的).只要您有一种唯一标识客户端的方法,在同一台计算机上拥有多个客户端是没有问题的(您在客户端登录时保存上下文).

I think this is the simplest way (not saying it's the best) to manage clients in the server. There is no problem with having multiple clients from the same computer (you save the Context when a client logges in) as long as you have a way of uniquely identify clients.

至于您的最后一个问题,拥有多个服务应该不是问题.事实上,对于您提供的不同服务,您拥有具有不同合同(和端点)的相同 WCF 服务器.所有合约都驻留在同一个 WCF 服务器实例中,因此它们都可以访问连接的客户端列表.

As for your last question, having multiple services should not be a problem. In fact you have the same WCF server with different contracts (and endpoints) for the different services you offer. ALl the contracts reside in the same WCF server instance so they all can access the connected client list.

如果您还有其他问题,我很乐意回答.

If you have further questions, I would be happy to answer them.

这篇关于wcf 操作上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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