zoukankan      html  css  js  c++  java
  • DuplexChannel

     [ServiceContract(Namespace = "http://xx.com", CallbackContract = typeof(Ipub_c))]
        public interface Ipub_s
        {
            [OperationContract(IsOneWay = true)]
            void toserver(string cs);
        }
        public interface Ipub_c
        {
            [OperationContract(IsOneWay = true)]
            void toclient(string cs);
    
        }
    
    
    
    
    
     [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
        public class Bpub : Ipub_s
        {
            public void toserver(string cs)
            {
    
                Ipub_c callback = OperationContext.Current.GetCallbackChannel<Ipub_c>();
                for (int i = 0; i < 1000; i++)
                {
                    System.Threading.Thread.Sleep(1000);
                    callback.toclient(cs + " | " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff") + " | " + cs);
                }
            }
        }
    
     ServiceHost host = new ServiceHost(typeof(Bpub));
                    host.AddServiceEndpoint(typeof(Ipub_s), new NetTcpBinding(), "net.tcp://localhost/dd");
                    host.Opened += (s, ek) =>
                    {
                        this.Invoke((Action)delegate
                        {
                            button1.Enabled = false;
                            button1.Text = "已启动";
                            Console.WriteLine("HelloService已经启动,按按回车键终止服务!");
                        });
                    };
                    host.Open();
    
         InstanceContext instanceContext = new InstanceContext(new Bcpub());
                DuplexChannelFactory<WcfSgS.Ipub_s> channel = new DuplexChannelFactory<Ipub_s>(instanceContext, new NetTcpBinding(), "net.tcp://localhost/dd");
                Ipub_s proxy = channel.CreateChannel();
    
    
                proxy.toserver("dddds");
    

      

  • 相关阅读:
    HNOI2003 消防局的设立
    APIO2007 风铃
    SDOI2006 保安站岗
    消息传递
    [POI2008]STA-Station
    JLOI2015 城池攻占
    BOI2004 sequence
    Monkey King
    APIO2012 Dispatching
    HTML meta 文本 格式排版 链接图表 列表 表单 frame后台布局实例
  • 原文地址:https://www.cnblogs.com/xiangxiong/p/6909664.html
Copyright © 2011-2022 走看看