/// <summary>
/// 会议服务 服务为单线程也就是只有一个实例,并且消息调用实例在第一次初始化的时候指明
/// </summary>
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Single, InstanceContextMode = InstanceContextMode.Single)]
public class MeetingService : AVA.Meeting.IService.IMeetingService
{
/// <summary>
/// 在这里保存进入当前会议的用户列表和回调方法
/// </summary>
public static Dictionary<IMeetingServiceCallback, ClientCallback>
ListCallbackToUser = new Dictionary<IMeetingServiceCallback, ClientCallback>();如的WCF每一个连接上来的用户我都保存到ListCallbackToUser里面
然后我要给他们发送信息比如用 void UpdateUserList()
{
foreach (IMeetingServiceCallback callbackClient in ListCallbackToUser.Keys)
{
try
{
callbackClient.UpdateUserList(ListCallbackToUser.Values.Select(l => l.User).ToList());
}
catch (System.ServiceModel.CommunicationObjectAbortedException)
{
}
}
}但是这里的:try catch这里能不能改为判断是否已经断开?(因为客户端可能没有向WCF更新断开信息,而还在WCF这里有他的登录信息,但其实他已经是断开 的)谢谢
解决方案 »
- 怎样简写下面的代码
- 怎么用正则表达式提取字符串里的内容
- 谁会用C#写九宫格,要求在窗体上显示,数字填写在文本框内
- 怎样做一个获得远方登陆用户IP的WEBSERVICE呢?
- 关于水晶报表的问题,高手帮个忙
- 在C#中如何利用SQL语句从数据库中取值 急急急急!!
- 如何对某个表中的列,进行验证,判断出某些列可以做加乘除等运算呢,而能做这些运算的列都是数字型列.
- 谁用过marconi_selenia RGG100的GSM-R手机.或者用过GSM-R手机开发的看过来.
- 这种情况下,如何设定comboBox的默认值?
- 我不太理解这些代码到底是怎么执行的呀?
- .net 2.0 怎么使用扩展方法?网上找的貌似不好使~很多分哦 可加分
- img 问题求大神 ?
using System.Collections.Generic;
using System.ServiceModel;
namespace WcfDuplexMessageService
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class MessageService : IMessageService, IDisposable
{
public static List<IClient> ClientCallbackList { get; set; }
public MessageService()
{
ClientCallbackList = new List<IClient>();
}
public void RegisterClient()
{
var client = OperationContext.Current.GetCallbackChannel<IClient>();
var id = OperationContext.Current.SessionId;
Console.WriteLine("{0} registered.", id);
OperationContext.Current.Channel.Closing += new EventHandler(Channel_Closing);
ClientCallbackList.Add(client);
}
void Channel_Closing(object sender, EventArgs e)
{
lock (ClientCallbackList)
{
ClientCallbackList.Remove((IClient)sender);
}
}
public void Dispose()
{
ClientCallbackList.Clear();
}
}
}