ProxyAttribute.CreateProxy(ObjRef, Type, Object, Context) 方法

定义

创建由指定的 ObjRef 描述并位于服务器上的远程对象的远程处理代理的实例。

public:
 virtual System::Runtime::Remoting::Proxies::RealProxy ^ CreateProxy(System::Runtime::Remoting::ObjRef ^ objRef, Type ^ serverType, System::Object ^ serverObject, System::Runtime::Remoting::Contexts::Context ^ serverContext);
public virtual System.Runtime.Remoting.Proxies.RealProxy CreateProxy (System.Runtime.Remoting.ObjRef objRef, Type serverType, object serverObject, System.Runtime.Remoting.Contexts.Context serverContext);
[System.Security.SecurityCritical]
public virtual System.Runtime.Remoting.Proxies.RealProxy CreateProxy (System.Runtime.Remoting.ObjRef objRef, Type serverType, object serverObject, System.Runtime.Remoting.Contexts.Context serverContext);
abstract member CreateProxy : System.Runtime.Remoting.ObjRef * Type * obj * System.Runtime.Remoting.Contexts.Context -> System.Runtime.Remoting.Proxies.RealProxy
override this.CreateProxy : System.Runtime.Remoting.ObjRef * Type * obj * System.Runtime.Remoting.Contexts.Context -> System.Runtime.Remoting.Proxies.RealProxy
[<System.Security.SecurityCritical>]
abstract member CreateProxy : System.Runtime.Remoting.ObjRef * Type * obj * System.Runtime.Remoting.Contexts.Context -> System.Runtime.Remoting.Proxies.RealProxy
override this.CreateProxy : System.Runtime.Remoting.ObjRef * Type * obj * System.Runtime.Remoting.Contexts.Context -> System.Runtime.Remoting.Proxies.RealProxy
Public Overridable Function CreateProxy (objRef As ObjRef, serverType As Type, serverObject As Object, serverContext As Context) As RealProxy

参数

objRef
ObjRef

对要为其创建代理的远程对象的对象引用。

serverType
Type

远程对象所在的服务器的类型。

serverObject
Object

服务器对象。

serverContext
Context

服务器对象所在的上下文。

返回

在指定的 ObjRef 中说明的远程对象的远程处理代理的新实例。

属性

示例

virtual RealProxy^ CreateProxy( ObjRef^ objRef1, Type^ serverType, Object^ serverObject, Context^ serverContext ) override
{
   MyProxy^ myCustomProxy = gcnew MyProxy( serverType );
   if ( serverContext != nullptr )
   {
      RealProxy::SetStubData( myCustomProxy, serverContext );
   }

   if ( ( !serverType->IsMarshalByRef) && (serverContext == nullptr) )
   {
      throw gcnew RemotingException( "Bad Type for CreateProxy" );
   }

   return myCustomProxy;
}
public override RealProxy CreateProxy(ObjRef objRef1,
   Type serverType,
   object serverObject,
   Context serverContext)
{
   MyProxy myCustomProxy = new MyProxy(serverType);
   if(serverContext != null)
   {
      RealProxy.SetStubData(myCustomProxy,serverContext);
   }
   if((!serverType.IsMarshalByRef)&&(serverContext == null))
   {
      throw new RemotingException("Bad Type for CreateProxy");
   }
   return myCustomProxy;
}
Public Overrides Function CreateProxy(objRef1 As ObjRef, serverType As Type, _
            serverObject As Object, serverContext As Context) As RealProxy
   Dim myCustomProxy As New MyProxy(serverType)
   If Not (serverContext Is Nothing) Then
      RealProxy.SetStubData(myCustomProxy, serverContext)
   End If
   If Not serverType.IsMarshalByRef And serverContext Is Nothing Then
      Throw New RemotingException("Bad Type for CreateProxy")
   End If
   Return myCustomProxy
End Function 'CreateProxy

注解

注意

从引用用 ProxyAttribute 特性标记的类的ObjRef实例创建代理时,将调用当前方法。 因此,仅当 ObjRef 在调用中从返回或参数收到 时,或在激活客户端激活对象期间,才使用 方法。 ProxyAttribute不用于已知对象类型。

适用于