【发布时间】:2012-08-07 08:41:12
【问题描述】:
我有以下问题。我正在写聊天软件。客户端/服务器机制基于 WCF 的 DualHttpBinding。这意味着如果用户发送消息,则服务器会通知发送消息房间中的所有客户端。
我想确保,如果客户端的应用程序崩溃(无论如何),客户端对象将从房间列表中删除。
是否有可能在调用回调操作之前检查回调通道的状态?问题是,如果我在不再连接的客户端上调用操作(由于意外崩溃),服务将挂起。
public YagzResult SendMessage(Message message)
{
foreach (ChatNodeAddress chatNodeAddress in message.Destination)
{
ChatNode chatNode = chatProvider.FindChatNode(chatNodeAddress);
if (chatNode != null)
{
User currentUser = CurrentUser;
foreach (User user in chatNode)
{
//Don't notify the current client. Deadlock!
if (!user.Equals(currentUser))
{
//Get the callback channel here
IYagzClient client = GetClientByUser(user);
if (client != null)
{
//--> If the client here called is not any more available,
//the service will hang <---
client.OnChatMessageReceived(message);
}
}
}
}
else
{
return YagzResult.ChatNodeNotFound;
}
}
return YagzResult.Ok;
}
如何检查客户是否仍在收听?顺便说一句,在客户端调用的操作都声明为 OneWay,并且 ConcurrencyMode 设置为“Multiple”。
谢谢大家!
你好,
西蒙
【问题讨论】:
标签: wcf client duplex-channel