我有以下问题。我正在写聊天软件。客户端/服务器机制基于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”。
谢谢你们!
Greets,
Simon
您可以将回调合约转换为通讯对象 http://msdn.microsoft.com/en-us/library/system.servicemodel.icommunicationobject.aspx然后检查通道状态。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)