藉助基維百科給它的定義以下:網絡
NET Remoting 是微軟 .NET Framework 中的一種網絡通信技術,與 XML Web Service 不一樣的是,它可使用 SOAP 之外的協定來通信,而在伺服端和用戶端之間所操做的方法近乎相同,用戶端能夠沒必要考慮使用的協定,便可存取伺服端所開放的物件。這個技術與是由Distributed COM所發展而來的,與DCOM最大的不一樣是,DCOM有限制使用 TCP Port,但.NET Remoting 能夠選擇使用 TCP 或 HTTP 的方式通信,而資料能夠利用 SOAP 或二進制傳輸方式在網絡上流動,二進制的傳輸效能是 SOAP 所不能比的,但 SOAP 卻能夠獲得和 Web Service 相互溝通的能力,所以 .NET Remoting 的設計彈性較大。app
.NET Remoting 技術目前已整合到 Windows Communication Foundation 中。url
.NET Remoting 使用了 Channel 和 Serialization 機制來串接兩臺機器間的物件,Channel 是負責處理網絡通信的部份,而 Serialization 則是處理物件與串流資料的處理工做。spa
當伺服端設定好使用的通道以及協定後,用戶端必需要跟隨伺服端的設定,而且依伺服端決定的活化模型來啓動,而程式設計的方法和通常呼叫元件般簡單。設計
public static void Main() { RemotingConfiguration.Configure("Client.exe.config"); // configure Remoting configuration. RemotableType remoteObject = new RemotableType(); // create remoting object. Console.WriteLine(remoteObject.SayHello()); // call remoting object's method. }
.NET Remoting 的設計理念,就是爲了要簡化網絡上的物件通信,並且要讓開發人員沒必要太過於在通信的底層傷腦筋,所以在網絡通信協定上作了許多的包裝,而且容許在 Configuration File(app.config)中直接設定,或是由 .NET Remoting 的 Configuration API 來設定便可,故組態設定的選項複雜度較高,設計較複雜的 .NET Remoting 應用程式在組態的設定上每每會至關複雜。code
如下爲設定 .NET Remoting 用戶端的範例設定:blog
<configuration> <system.runtime.remoting> <application> <client> <wellknown type="RemotableType, RemotableType" url="http://localhost:8989/RemotableType.rem" /> </client> </application> </system.runtime.remoting> </configuration>
活化(Activation)是指用戶端啓動伺服端元件的方式,.NET Remoting 中支援了兩種方式[3]:繼承
在 .NET Remoting 中,不管是傳值或傳址,每個物件都必需要繼承 System.MarshalByRefObject 類別,才能夠利用 .NET Remoting 來傳輸[4]。ip
如下程式碼爲服務端的 Remoting 元件:ci
// RemotableType.cs using System; public class RemotableType : MarshalByRefObject // Remoting 物件必須繼承自 System.MarshalByRefObject 類別。 { public string SayHello() { Console.WriteLine("RemotableType.SayHello() was called!"); return "Hello, world"; } }