RemotingServices.Marshal 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将给定的 MarshalByRefObject 转换为 ObjRef 类的实例,可以将该实例序列化以便在应用程序域之间以及通过网络进行传输。
重载
Marshal(MarshalByRefObject) |
接受 MarshalByRefObject,将其注册到远程处理基础结构,然后将其转换为 ObjRef 类的实例。 |
Marshal(MarshalByRefObject, String) |
将给定的 MarshalByRefObject 转换为具有指定 URI 的 ObjRef 类的实例。 |
Marshal(MarshalByRefObject, String, Type) |
接受 MarshalByRefObject,并将其转换为具有指定 URI 和提供的 ObjRef 的 Type 类的实例。 |
Marshal(MarshalByRefObject)
接受 MarshalByRefObject,将其注册到远程处理基础结构,然后将其转换为 ObjRef 类的实例。
public:
static System::Runtime::Remoting::ObjRef ^ Marshal(MarshalByRefObject ^ Obj);
public static System.Runtime.Remoting.ObjRef Marshal (MarshalByRefObject Obj);
static member Marshal : MarshalByRefObject -> System.Runtime.Remoting.ObjRef
Public Shared Function Marshal (Obj As MarshalByRefObject) As ObjRef
参数
要转换的对象。
返回
ObjRef 类的一个实例,它表示 Obj
参数中指定的对象。
例外
Obj
参数是一个对象代理。
在调用堆栈上部,至少有一个调用方没有配置远程处理类型和通道的权限。
注解
是 ObjRef 用于跨应用程序域边界传输对象引用的对象的可序列化表示形式。 ObjRef为 对象创建 称为封送处理。 ObjRef可以通过通道将 传输到另一个应用程序域, (可能在另一个进程或计算机上) 。 进入另一个应用程序域后, ObjRef 必须分析 才能为 对象创建代理,通常连接到实际对象。 此操作称为 unmarshaling。
ObjRef包含描述Type要封送的 对象的 和 类的信息、唯一标识特定对象实例的 URI,以及有关如何访问对象所在远程处理细分的通信相关信息。
在封送处理期间,将使用当前线程中的上下文,而不是创建对象时处于活动状态的上下文。 如果方法未显式设置 SetObjectUriForMarshal URI,则远程处理标识基础结构会自动生成该 URI。
由于以下两个原因之一,无法将 URI 与代理关联:该 URI 是在服务器端为其表示的对象生成的,或者对象是已知的,在这种情况下,URI 是已知的。 因此,如果 Obj
参数是代理,则会引发异常。 对于自定义代理,由于透明代理被视为服务器对象,因此会放宽此限制。
另请参阅
适用于
Marshal(MarshalByRefObject, String)
将给定的 MarshalByRefObject 转换为具有指定 URI 的 ObjRef 类的实例。
public:
static System::Runtime::Remoting::ObjRef ^ Marshal(MarshalByRefObject ^ Obj, System::String ^ URI);
public static System.Runtime.Remoting.ObjRef Marshal (MarshalByRefObject Obj, string URI);
static member Marshal : MarshalByRefObject * string -> System.Runtime.Remoting.ObjRef
Public Shared Function Marshal (Obj As MarshalByRefObject, URI As String) As ObjRef
参数
要转换的对象。
返回
ObjRef 类的一个实例,它表示 Obj
参数中指定的对象。
例外
Obj
是一个对象代理,URI
参数不为 null
。
在调用堆栈上部,至少有一个调用方没有配置远程处理类型和通道的权限。
示例
下面的代码示例演示如何使用当前 Marshal 方法封送指定的 对象。
TcpChannel^ channel = gcnew TcpChannel( 9000 );
ChannelServices::RegisterChannel( channel );
SampleWellKnown ^ objectWellKnown = gcnew SampleWellKnown;
// After the channel is registered, the Object* needs to be registered
// with the remoting infrastructure. So, Marshal is called.
ObjRef^ objrefWellKnown = RemotingServices::Marshal( objectWellKnown, "objectWellKnownUri" );
Console::WriteLine( "An instance of SampleWellKnown type is published at {0}.", objrefWellKnown->URI );
Console::WriteLine( "Press enter to unregister SampleWellKnown, so that it is no longer available on this channel." );
Console::ReadLine();
RemotingServices::Disconnect( objectWellKnown );
Console::WriteLine( "Press enter to end the server process." );
Console::ReadLine();
TcpChannel channel = new TcpChannel(9000);
ChannelServices.RegisterChannel(channel);
SampleWellKnown objectWellKnown = new SampleWellKnown();
// After the channel is registered, the object needs to be registered
// with the remoting infrastructure. So, Marshal is called.
ObjRef objrefWellKnown = RemotingServices.Marshal(objectWellKnown, "objectWellKnownUri");
Console.WriteLine("An instance of SampleWellKnown type is published at {0}.", objrefWellKnown.URI);
Console.WriteLine("Press enter to unregister SampleWellKnown, so that it is no longer available on this channel.");
Console.ReadLine();
RemotingServices.Disconnect(objectWellKnown);
Console.WriteLine("Press enter to end the server process.");
Console.ReadLine();
Dim channel As New TcpChannel(9000)
ChannelServices.RegisterChannel(channel)
Dim objectWellKnown As New SampleWellKnown()
' After the channel is registered, the object needs to be registered
' with the remoting infrastructure. So, Marshal is called.
Dim objrefWellKnown As ObjRef = RemotingServices.Marshal(objectWellKnown, "objectWellKnownUri")
Console.WriteLine("An instance of SampleWellKnown type is published at {0}.", objrefWellKnown.URI)
Console.WriteLine("Press enter to unregister SampleWellKnown, so that it is no longer available on this channel.")
Console.ReadLine()
RemotingServices.Disconnect(objectWellKnown)
Console.WriteLine("Press enter to end the server process.")
Console.ReadLine()
注解
是 ObjRef 用于跨应用程序域边界传输对象引用的对象的可序列化表示形式。 ObjRef为 对象创建 称为封送处理。 ObjRef可以通过通道将 传输到另一个应用程序域, (可能在另一个进程或计算机上) 。 进入另一个应用程序域后, ObjRef 必须分析 才能为 对象创建代理,通常连接到实际对象。 此操作称为 unmarshaling。
ObjRef包含描述Type要封送的 对象的 和 类的信息、唯一标识特定对象实例的 URI,以及有关如何访问对象所在远程处理细分的通信相关信息。
在封送处理期间,将使用当前线程中的上下文,而不是创建对象时处于活动状态的上下文。
由于以下两个原因之一,无法将 URI 与代理关联:该 URI 是在服务器端为其表示的对象生成的,或者对象是已知的,在这种情况下,URI 是已知的。 因此,如果 Obj
参数是代理,则会引发异常。 对于自定义代理,由于透明代理被视为服务器对象,因此会放宽此限制。
另请参阅
适用于
Marshal(MarshalByRefObject, String, Type)
接受 MarshalByRefObject,并将其转换为具有指定 URI 和提供的 ObjRef 的 Type 类的实例。
public:
static System::Runtime::Remoting::ObjRef ^ Marshal(MarshalByRefObject ^ Obj, System::String ^ ObjURI, Type ^ RequestedType);
public static System.Runtime.Remoting.ObjRef Marshal (MarshalByRefObject Obj, string ObjURI, Type RequestedType);
static member Marshal : MarshalByRefObject * string * Type -> System.Runtime.Remoting.ObjRef
Public Shared Function Marshal (Obj As MarshalByRefObject, ObjURI As String, RequestedType As Type) As ObjRef
参数
要转换为 ObjRef 的对象。
- ObjURI
- String
URI,使用它对 Obj
参数中指定的对象进行封送。 可以为 null
。
返回
ObjRef 类的一个实例,它表示 Obj
参数中指定的对象。
例外
Obj
是远程对象的代理,ObjUri
参数不为 null
。
在调用堆栈上部,至少有一个调用方没有配置远程处理类型和通道的权限。
注解
是 ObjRef 用于跨应用程序域边界传输对象引用的对象的可序列化表示形式。 ObjRef为 对象创建 称为封送处理。 ObjRef可以通过通道将 传输到另一个应用程序域, (可能在另一个进程或计算机上) 。 进入另一个应用程序域后, ObjRef 必须分析 才能为 对象创建代理,通常连接到实际对象。 此操作称为 unmarshaling。
ObjRef包含描述Type要封送的 对象的 和 类的信息、唯一标识特定对象实例的 URI,以及有关如何访问对象所在远程处理细分的通信相关信息。
指定的 Type 由远程处理基础结构用来限制公开的类型层次结构的范围。 例如,如果对象 A 派生自对象 B,后者派生自对象 C,并且被调用,则客户端可以在 C 和 Marshal B 之间将代理强制转换为 A,但不能强制转换为 A。
在封送处理期间,将使用当前线程中的上下文,而不是创建对象时处于活动状态的上下文。
由于以下两个原因之一,无法将 URI 与代理关联:该 URI 是在服务器端为其表示的对象生成的,或者对象是已知的,在这种情况下,URI 是已知的。 因此,如果 Obj
参数是代理,则会引发异常。 对于自定义代理,由于透明代理被视为服务器对象,因此会放宽此限制。