zoukankan      html  css  js  c++  java
  • 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}	{1}	{2}", value, GetClientIP(), AppDomain.CurrentDomain.ToString());
                Log(result);
                System.Threading.Thread.Sleep(500);
    
                Log("Leave:{0}	{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();

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

  • 相关阅读:
    luogu P3295 [SCOI2016]萌萌哒
    luogu P4916 魔力环
    CF997C Sky Full of Stars
    CF961G Partitions
    android屏蔽软键盘并且显示光标
    设置和获取Android中各种音量
    自定义广播
    发送广播
    android取高度
    Java数字格式化
  • 原文地址:https://www.cnblogs.com/xiaotiannet/p/3423266.html
Copyright © 2011-2022 走看看