共用方式為


RealProxy.SetStubData(RealProxy, Object) 方法

定義

設定指定 Proxy 的 Stub 資料。

public:
 static void SetStubData(System::Runtime::Remoting::Proxies::RealProxy ^ rp, System::Object ^ stubData);
public static void SetStubData (System.Runtime.Remoting.Proxies.RealProxy rp, object stubData);
[System.Security.SecurityCritical]
public static void SetStubData (System.Runtime.Remoting.Proxies.RealProxy rp, object stubData);
static member SetStubData : System.Runtime.Remoting.Proxies.RealProxy * obj -> unit
[<System.Security.SecurityCritical>]
static member SetStubData : System.Runtime.Remoting.Proxies.RealProxy * obj -> unit
Public Shared Sub SetStubData (rp As RealProxy, stubData As Object)

參數

rp
RealProxy

要為之設定 Stub 資料的 Proxy。

stubData
Object

新 Stub 資料。

屬性

例外狀況

目前的呼叫端沒有 UnmanagedCode 權限。

範例

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

備註

自訂 Proxy 使用者會使用存根數據來決定使用傳入方法呼叫的動作。 例如,存根數據可能是伺服器內容的相關信息,可用來判斷是否要在本機執行呼叫,或透過遠端基礎結構傳送它。

適用於