天天看點

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 宿主 釋出