C# WCF寄宿笔记

  private ServiceHost m_serviceHost;
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Init()
        {
            m_serviceHost = HostWithWebHttp(typeof(Service1), typeof(IService1), "/Service1");
            m_serviceHost.Opened += delegate
            {
                Console.WriteLine("WCF服务已经启动");
            };
            m_serviceHost.Open();
        }
        private ServiceHost HostWithWebHttp(Type serviceType, Type interfaceType, string endPoint)
        {
            string baseAddress = string.Format("http://{0}","127.0.0.1:3000");
            ServiceHost host = new ServiceHost(serviceType);
            WebHttpBinding binding = new WebHttpBinding();
            binding.MaxBufferPoolSize = 20971520;
            binding.MaxReceivedMessageSize = 20971520;
            binding.MaxBufferSize = 20971520;
            binding.WriteEncoding = Encoding.UTF8;
            ServiceEndpoint endpoint = host.AddServiceEndpoint(interfaceType, binding, baseAddress + endPoint);
            endpoint.Behaviors.Add(new WebHttpBehavior());
            return host;
        }

转载于:https://www.cnblogs.com/zebra-bin/p/11059449.html

猜你喜欢

转载自blog.csdn.net/weixin_34062469/article/details/93672493