WCF後續之旅(14):TCP端口共享
在下麵的例子中,我通過兩個不同的控製台應用程序對兩個服務,Service1和Service2進行寄宿,兩個服務的終結點地址共享相同的端口:。
1: using(ServiceHost serviceHost = new ServiceHost(typeof(Service1)))
2: {
3: serviceHost.AddServiceEndpoint(typeof(IService1), new NetTcpBinding(), "net.tcp://127.0.0.1:9999/service1");
4: serviceHost.Open();
5: Console.Read();
6: }
1: using(ServiceHost serviceHost = new ServiceHost(typeof(Service2)))
2: {
3: serviceHost.AddServiceEndpoint(typeof(IService2), new NetTcpBinding(), "net.tcp://127.0.0.1:9999/service2");
4: serviceHost.Open();
5: Console.Read();
6: }
二、Net.TCP Port Sharing Service
三 、基於TCP端口共享的編程
注:通過“開始”-〉“控製麵板”-〉“管理工具”-〉服務,打開如下圖所示的“服務對話框”,然後定位到Net.TCP Port Sharing Service。
1: public class NetTcpBinding : Binding, IBindingRuntimePreferences
2: {
3: // ... ...
4: public bool PortSharingEnabled { get; set; }
5: }
1: using(ServiceHost serviceHost = new ServiceHost(typeof(Service1)))
2: {
3: NetTcpBinding binding = new NetTcpBinding();
4: binding.PortSharingEnabled = true;
5: serviceHost.AddServiceEndpoint(typeof(IService1),binding,"net.tcp://127.0.0.1:9999/service1");
6: serviceHost.Open();
7: Console.Read();
8: }
1: <configuration>
2: <system.serviceModel>
3: <bindings>
4: <netTcpBinding>
5: <binding name="portSharingBinding" portSharingEnabled="true" />
6: </netTcpBinding>
7: </bindings>
8: <services>
9: <service name="Artech.WcfServices.Services.CalculateService">
10: <endpoint binding="netTcpBinding" bindingConfiguration="portSharingBinding"
11: contract="Artech.WcfServices.Contracts.ICalculate" />
12: </service>
13: </services>
14: </system.serviceModel>
15: </configuration>
WCF後續之旅:
WCF後續之旅(1): WCF是如何通過Binding進行通信的
WCF後續之旅(2): 如何對Channel Layer進行擴展——創建自定義Channel
WCF後續之旅(3): WCF Service Mode Layer 的中樞—Dispatcher
WCF後續之旅(4):WCF Extension Point 概覽
WCF後續之旅(5): 通過WCF Extension實現Localization
WCF後續之旅(6): 通過WCF Extension實現Context信息的傳遞
WCF後續之旅(7):通過WCF Extension實現和Enterprise Library Unity Container的集成
WCF後續之旅(8):通過WCF Extension 實現與MS Enterprise Library Policy Injection Application Block 的集成
WCF後續之旅(9):通過WCF的雙向通信實現Session管理[Part I]
WCF後續之旅(9): 通過WCF雙向通信實現Session管理[Part II]
WCF後續之旅(10): 通過WCF Extension實現以對象池的方式創建Service Instance
WCF後續之旅(11): 關於並發、回調的線程關聯性(Thread Affinity)
WCF後續之旅(12): 線程關聯性(Thread Affinity)對WCF並發訪問的影響
WCF後續之旅(13): 創建一個簡單的WCF SOAP Message攔截、轉發工具[上篇]
WCF後續之旅(13):創建一個簡單的SOAP Message攔截、轉發工具[下篇]
WCF後續之旅(14):TCP端口共享
WCF後續之旅(15): 邏輯地址和物理地址
WCF後續之旅(16): 消息是如何分發到Endpoint的--消息篩選(Message Filter)
WCF後續之旅(17):通過tcpTracer進行消息的路由
微信公眾賬號:大內老A
微博:www.weibo.com/artech
如果你想及時得到個人撰寫文章以及著作的消息推送,或者想看看個人推薦的技術資料,可以掃描左邊二維碼(或者長按識別二維碼)關注個人公眾號(原來公眾帳號蔣金楠的自媒體將會停用)。
本文版權歸作者和博客園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁麵明顯位置給出原文連接,否則保留追究法律責任的權利。
最後更新:2017-10-30 16:34:35