WCF服务对于处理客户端连接的一点思考

对于每个客户端的,服务端是否为每个客户端有专门的“通道”?

目的:想在服务端记录下来客户端的访问记录(进入、各个操作、离开等信息),并将其执行的操作独立记录在各个客户端对应的日志中。

下面是代码:

契约

    [ServiceContract]
    public interface IService
    {

        [OperationContract]
        string GetData(string value);
       
    }

服务

    public class Service : IService
    {


        public string GetData(string value)
        {

            string result = string.Format("Enter:{0}\t{1}\t{2}", value, GetClientIP(), AppDomain.CurrentDomain.ToString());
            Log(result);
            System.Threading.Thread.Sleep(500);

            Log("Leave:{0}\t{1}", value, GetClientIP());
            return result;

        }
     }

客户端

System.Timers.Timer timer1 = new System.Timers.Timer();
                timer1.Interval = 2000;
                timer1.Elapsed +=
               delegate
               {
                   while (true)
                   {


                       ChannelFactory<IService> channelFatory = GetChannelFactory<IService>("BasicHttpBinding_IService1");

                       IService1 calculator = channelFatory.CreateChannel();
                       try
                       {
                           Console.WriteLine(calculator.GetData(IP));
                       }
                       finally
                       {
                           CloseConnection((calculator as ICommunicationObject));
                       }


                   }
               };
                timer1.Start();

 

最后证明:服务为每个客户端连接开辟了单独的通道。不知道我的理解正确不。。。。待续

转载于:https://www.cnblogs.com/xiaotiannet/p/3423266.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值