天天看点

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();
                }
            }      

作者:释迦苦僧

出处:http://www.cnblogs.com/woxpp

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。

生活不易,五行缺金,求打点

WCF 基于 WinForm 宿主 发布