WCF常见问题之端口共享
2011-05-14 14:00
267 查看
当两个WCF应用程序想共享一个端口提供服务时,你会发现后一个启动的服务运行不了,会提示已经有应用程序在监听,如:
应用一
![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
代码
ServiceHost host = new ServiceHost(typeof(WCFPortSharing.AddService));
NetTcpBinding binding = new NetTcpBinding();
host.AddServiceEndpoint(typeof(WCFPortSharing.IAddService), binding, "net.tcp://127.0.0.1:4503/addService");
host.Open();
应用二
![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
代码
ServiceHost host1 = new ServiceHost(typeof(WCFPortSharing.SubService));
NetTcpBinding binding1 = new NetTcpBinding();
host1.AddServiceEndpoint(typeof(WCFPortSharing.ISubService), binding1, "net.tcp://127.0.0.1:4503/subService");
host1.Open();
如果想不冲突,需要开启WCF的端口共享,并启动一个服务Net.Tcp Port Sharing Service,此服务默认是禁止运行的,手动开启后,将服务配置加上
binding.PortSharingEnabled = true;
这样:
![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
代码
ServiceHost host = new ServiceHost(typeof(WCFPortSharing.AddService));
NetTcpBinding binding = new NetTcpBinding();
binding.PortSharingEnabled = true;
host.AddServiceEndpoint(typeof(WCFPortSharing.IAddService), binding, "net.tcp://127.0.0.1:4503/addService");
host.Open();
应用一
![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
代码
ServiceHost host = new ServiceHost(typeof(WCFPortSharing.AddService));
NetTcpBinding binding = new NetTcpBinding();
host.AddServiceEndpoint(typeof(WCFPortSharing.IAddService), binding, "net.tcp://127.0.0.1:4503/addService");
host.Open();
应用二
![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
代码
ServiceHost host1 = new ServiceHost(typeof(WCFPortSharing.SubService));
NetTcpBinding binding1 = new NetTcpBinding();
host1.AddServiceEndpoint(typeof(WCFPortSharing.ISubService), binding1, "net.tcp://127.0.0.1:4503/subService");
host1.Open();
如果想不冲突,需要开启WCF的端口共享,并启动一个服务Net.Tcp Port Sharing Service,此服务默认是禁止运行的,手动开启后,将服务配置加上
binding.PortSharingEnabled = true;
这样:
![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
代码
ServiceHost host = new ServiceHost(typeof(WCFPortSharing.AddService));
NetTcpBinding binding = new NetTcpBinding();
binding.PortSharingEnabled = true;
host.AddServiceEndpoint(typeof(WCFPortSharing.IAddService), binding, "net.tcp://127.0.0.1:4503/addService");
host.Open();
相关文章推荐
- WCF常见问题之端口共享
- WCF常见问题之端口共享
- WCF常见问题之端口共享
- WCF常见问题之端口共享
- Tomcat(8005,8080,8009)端口占用问题常见原因及解决方法
- 用IIS 承载 WCF 的配置步骤 及 常见问题处理
- Tomcat(8005,8080,8009)端口占用问题常见原因及解决方法
- 什么条件下IIS与WCF服务可以共享一个端口?
- 让疑问归零:宽带共享常见经典问题
- IIS托管的WCF服务的常见Setup问题
- 启用WCF NetTcpBinding的共享端口
- WCF常见问题(2) -- Winform Host UI阻塞
- 【Unity】近期整理Unity4.x 项目升级Unity5.0 过程中出现的各种常见问题,与大家共享。
- 分布式系统开发常见问题-1. session的复制与共享 2. 分布式缓存的设计
- WCF常见问题记忆
- WCF开发框架形成之旅--WCF应用常见问题处理
- WCF常见问题
- 同域名下不同端口 cookie共享冲突问题
- 于国富:共享软件作者常见法律问题
- WCF常见问题(1) -- WebService/WCF Session Cookie