WCF 基于 WinForm 宿主 发布

来源:互联网 发布:数据帧格式设计 编辑:程序博客网 时间:2024/06/05 00:32

BasicHttpBinding

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


 

NetTcpBinding

  

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


 

 

 NetNamedPipeBinding

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