多个数据合约回调合约

发布于 2024-08-20 11:27:12 字数 133 浏览 7 评论 0原文

问候, 我们公司正在开发wcf服务。这是用作服务器并且工作得很好。将鼠标悬停在客户的愿望上,他们希望在登录应用程序后查看哪些用户也登录了。 我读到了 CallbackContract (基于一些 wcf 聊天应用程序)。我们怎样才能实现这个目标呢?

Greetings,
in our company we are developing wcf service. This is used as a server and it works quite well. Hover there is a wish from customer that after they login to application they would like to see which users are logged in too.
I read about CallbackContract (based on some wcf chat application). How can we achive this goal?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贵在坚持 2024-08-27 11:27:12

此处提出了类似的问题

您可以对服务器内的登录用户进行明确的管理。我创建了一个处理此类情况的个人模式,通常是这样的:

  • 在 WCF 服务器内创建一个客户端类,该类将保存有关客户端的所有所需信息。

  • 在服务中创建2个方法:logIn、logOut。登录方法应该能够收集有关您要存储的客户端的所有信息。确保定义可以唯一标识客户端实例的属性。当客户端连接到服务器时,它调用登录方法,允许服务器收集并保存来自客户端的信息。如果使用回调,这是在客户端对象中保存 CallBack 上下文对象的位置。您现在可以将 Client 对象保存在 WCF 服务器实例中(我使用字典)。当客户端注销时,它会调用注销方法,服务器会删除该条目。

  • 在服务器中创建一个 KeepAlive 方法,定期检查连接的客户端以查看它们是否仍然连接(如果出现网络故障或应用崩溃,客户端可能不会调用注销方法)。

我认为这是最简单的方法(不是
说这是最好的)管理
服务器中的客户端。没有
拥有多个客户端的问题
从同一台计算机(您保存
客户端登录时的上下文)为
只要你有独特的方法
识别客户。

至于你的最后一个问题,
多项服务不应该是一个
问题。事实上你有相同的WCF
具有不同合约的服务器(以及
端点)用于不同的服务
你提供。所有合同都位于
相同的 WCF 服务器实例,因此它们
所有人都可以访问连接的客户端
列表。

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

您可以在此处找到实际构建所需的 WCF 服务所需的代码

Similar question asked here

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:

  • create a client class inside the WCF server that will hold all the needed information about the client.

  • create 2 methods in the service: logIn, logOut. the login method should be able to gather all the informations about the client that you want to store. Make sure to define properties that can uniquely identify a client instance. When the client conencts to the server it calls the login method, allowing the server to gather and save the information from the client. If using callbacks, this is the place to save the CallBack context object, in the client obejt. You can now save the Client object in the WCF server instance (I use a dictioary). When the client logs out, it calls the log out method and the server removes the entry.

  • create a KeepAlive method in the server that regularry checks the connected clients to see if they are still connected (in case of network failure or app crash a client may not call the logout method).

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.

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.

You can find the code you need to actually build the WCF service you require here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文