在對等網路中模擬WCF單工訊息交換模式

2021-05-28 14:09:43 字數 1465 閱讀 8046

在wcf中有三種訊息交換模式(message exchange pattern,mep),包括單向通訊模式、雙工通訊模式、請求-響應通訊模式,其通過5種不同的通道來實現,其中不是每一種繫結都能支援這些通道,具體可以通過程式進行檢測,可參考之前的檢測結果。從其中可以看出對於單向通訊模式的(iinputchannel和ioutputchannel)只有msmqintegrationbinding、netmsmqbinding和netpeertcpbinding三種繫結在定製的基礎上支援。本文介紹在vs2010 .net 4.0.30319環境下,利用netpeertcpbinding這種定製的繫結模擬單向通訊模式的實現。

其中建立兩個控制台應用程式,具體的結構如下圖所示:

其中inputoutputserver是服務端,同時提供p2p名字解析的服務,負責偵聽客戶端請求,並用iinputchannel接收訊息;inputoutputclient是客戶端,通過ioutputchannel傳送訊息至服務端。其中需要額外引入幾個程式庫,圖中已有標註。

inputoutputserver端的program.cs檔案為:

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.servicemodel;

using system.servicemodel.channels;

using system.runtime.serialization;

using system.servicemodel.security;

using system.net.peertopeer;

using system.servicemodel.peerresolvers;

namespace inputoutputserver}}

<?xml version="1.0" encoding="utf-8" ?>

inputoutputclient端的program.cs檔案為:

using system;

using system.collections.generic;

using system.linq;

using system.text;

using system.servicemodel;

using system.servicemodel.channels;

using system.runtime.serialization;

namespace inputoutputclient}}

先執行inputoutputserver端,然後執行inputoutputclient端,其執行結果為:

服務端客戶端

此種模式若存在錯誤很難進行跟蹤。

對等網路與非對等網路

對等網路 網上各台計算機有相同的功能,無主從之分,任一台計算機都是即可作為伺服器,設定共享資源供網路中其他計算機所使用,如果前面加個lb 負載均衡 伺服器就可以均勻排程,減輕伺服器的壓力 非對等網路,聯網計算機都有明確的分工。網路伺服器採用高配置與高效能的計算機,以集中方式管理區域網的共享資源,並為...

對等網路 P2P 網路大典

對等網路 p2p 屬於網路型別之一,該網路中的計算機相互之間可以直接通訊,而不需要通過中心伺服器。對等 或p2p 型計算機網路是通過大量的對等節點連線任意網路,這些對等節點承擔網路中其它對應節點的客戶機和伺服器的執行任務。這種網路分配模式與客戶機 伺服器模式形成對比。該模式中,任意節點都能啟動或完成...

C PeerToPeer(對等網路P2P 例項

在 net framework 3.5以上的.net框架,system.net.dll 程式集中新增了system.net.peertopeer 命名空間,它提供了輕鬆建立對等網路 p2p 應用程式所需的核心構建基塊。該命名空間是根據典型的 p2p 應用程式的三個階段而設計的,即 發現 連線和通訊 ...