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://files.cnblogs.com/files/woxpp/QQ%E6%88%AA%E5%9B%BE20161229110254.bmp)