WCF 基于 WinForm 宿主 发布

      ServiceHost Host = new ServiceHost(typeof(ServiceHTTP));

            //绑定 
            System.ServiceModel.Channels.Binding httpBinding = new BasicHttpBinding();
            //终结点 
            Host.AddServiceEndpoint(typeof(IServiceHTTP), httpBinding, "http://localhost:8732/WcfHTTPService");
            if (Host.Description.Behaviors.Find<System.ServiceModel.Description.ServiceMetadataBehavior>() == null)
            {
                //行为 
                ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                behavior.HttpGetEnabled = true;

                //元数据地址 
                behavior.HttpGetUrl = new Uri("http://localhost:8732/WcfHTTPService");
                Host.Description.Behaviors.Add(behavior);

                //启动 
                if (Host.State != CommunicationState.Opened)
                {
                    Host.Open();
                }
            }
ServiceHost Host = new ServiceHost(typeof(ServiceTCP));

            //绑定 
            System.ServiceModel.Channels.Binding netTcp = new NetTcpBinding();
            //终结点 
            Host.AddServiceEndpoint(typeof(IServiceTCP), netTcp, "net.tcp://192.168.1.88:54321/TCPService");
            if (Host.Description.Behaviors.Find<System.ServiceModel.Description.ServiceMetadataBehavior>() == null)
            {
                //行为 
                ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                behavior.HttpGetEnabled = true;

                //元数据地址 
                behavior.HttpGetUrl = new Uri("http://localhost:8730/WcfTCPService");
                Host.Description.Behaviors.Add(behavior);

                //启动 
                if (Host.State != CommunicationState.Opened)
                {
                    Host.Open();
                }
            }
   ServiceHost Host = new ServiceHost(typeof(ServiceIPC));

            //绑定 
            System.ServiceModel.Channels.Binding httpBinding = new NetNamedPipeBinding();
            //终结点 
            Host.AddServiceEndpoint(typeof(IServiceIPC), httpBinding, "net.pipe://localhost/IPCService");
            if (Host.Description.Behaviors.Find<System.ServiceModel.Description.ServiceMetadataBehavior>() == null)
            {
                //行为 
                ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                behavior.HttpGetEnabled = true;

                //元数据地址 
                behavior.HttpGetUrl = new Uri("http://localhost:8006/WcfIPCService");
                Host.Description.Behaviors.Add(behavior);

                //启动 
                if (Host.State != CommunicationState.Opened)
                {
                    Host.Open();
                }
            }

 

posted @ 2016-12-29 12:09  释迦苦僧  阅读(556)  评论(0编辑  收藏  举报