借助基维百科给它的定义以下:网络
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"; } }