26 private object _identity;
30 private RealProxyFlags _flags;
34 internal int _optFlags;
36 internal int _domainID;
38 private static IntPtr _defaultStub;
40 private static IntPtr _defaultStubValue;
42 private static object _defaultStubData;
44 internal bool Initialized
48 return (_flags & RealProxyFlags.Initialized) == RealProxyFlags.Initialized;
54 _flags |= RealProxyFlags.Initialized;
58 _flags &= ~RealProxyFlags.Initialized;
65 internal virtual Identity IdentityObject
67 [ReliabilityContract(
Consistency.WillNotCorruptState,
Cer.Success)]
70 return (Identity)_identity;
78 [SecuritySafeCritical]
81 _defaultStub = GetDefaultStub();
82 _defaultStubValue =
new IntPtr(-1);
83 _defaultStubData = _defaultStubValue;
92 : this(classToProxy, (
IntPtr)0, null)
112 stubData = _defaultStubData;
115 if (stubData ==
null)
119 _tp =
RemotingServices.CreateTransparentProxy(
this, classToProxy, stub, stubData);
120 RemotingProxy remotingProxy =
this as RemotingProxy;
121 if (remotingProxy !=
null)
123 _flags |= RealProxyFlags.RemotingProxy;
127 internal bool IsRemotingProxy()
129 return (_flags & RealProxyFlags.RemotingProxy) == RealProxyFlags.RemotingProxy;
141 if (_serverObject ==
null)
149 SetContextForDefaultStub();
171 object[] array = methodReturnMessage?.
OutArgs;
172 int outArgsCount = (array !=
null) ? array.Length : 0;
174 result =
new ConstructorReturnMessage(marshalByRefObject, array, outArgsCount, callCtx, ctorMsg);
176 if (IsRemotingProxy())
178 ((RemotingProxy)
this).Initialized =
true;
183 result =
new ConstructorReturnMessage(ex, ctorMsg);
195 return UnwrappedServerObject;
205 if (transparentProxy !=
null)
210 _serverObject =
null;
211 serverObject.__ResetServerIdentity();
222 if (transparentProxy !=
null)
226 AttachServerHelper(s);
230 private void SetupIdentity()
232 if (_identity ==
null)
234 _identity = IdentityHolder.FindOrCreateServerIdentity(_serverObject,
null, 0);
240 private void SetContextForDefaultStub()
242 if (GetStub() == _defaultStub)
245 if (stubData is
IntPtr && ((
IntPtr)stubData).Equals(_defaultStubValue))
253 internal bool DoContextsMatch()
256 if (GetStub() == _defaultStub)
268 internal void AttachServerHelper(MarshalByRefObject s)
270 if (s ==
null || _serverObject !=
null)
272 throw new ArgumentException(Environment.GetResourceString(
"ArgumentNull_Generic"),
"s");
279 private extern IntPtr GetStub();
287 public static extern void SetStubData(RealProxy rp,
object stubData);
289 internal void SetSrvInfo(
GCHandle srvIdentity,
int domainID)
291 _srvIdentity = srvIdentity;
292 _domainID = domainID;
301 public static extern object GetStubData(RealProxy rp);
304 private static extern IntPtr GetDefaultStub();
323 if (_identity ==
null)
346 if (retMsg ==
null || methodReturnMessage ==
null)
351 if (exception !=
null)
353 throw exception.PrepForRemoting();
355 if (!(retMsg is StackBasedReturnMessage))
357 if (reqMsg is Message)
359 PropagateOutParameters(reqMsg, methodReturnMessage.
Args, methodReturnMessage.
ReturnValue);
361 else if (reqMsg is ConstructorCallMessage)
363 PropagateOutParameters(reqMsg, methodReturnMessage.
Args,
null);
369 internal static void PropagateOutParameters(
IMessage msg,
object[] outArgs,
object returnValue)
374 ConstructorCallMessage constructorCallMessage = msg as ConstructorCallMessage;
375 if (constructorCallMessage !=
null)
377 message = constructorCallMessage.GetMessage();
382 throw new ArgumentException(Environment.GetResourceString(
"Remoting_Proxy_ExpectedOriginalMessage"));
384 MethodBase methodBase = message.GetMethodBase();
385 RemotingMethodCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(methodBase);
386 if (outArgs !=
null && outArgs.Length != 0)
388 object[] args = message.Args;
389 ParameterInfo[] parameters = reflectionCachedData.Parameters;
390 int[] marshalRequestArgMap = reflectionCachedData.MarshalRequestArgMap;
391 foreach (
int num
in marshalRequestArgMap)
396 outArgs[num] = args[num];
399 if (reflectionCachedData.NonRefOutArgMap.Length != 0)
401 int[] nonRefOutArgMap = reflectionCachedData.NonRefOutArgMap;
402 foreach (
int num2
in nonRefOutArgMap)
404 Array array = args[num2] as Array;
407 Array.Copy((Array)outArgs[num2], array, array.Length);
411 int[] outRefArgMap = reflectionCachedData.OutRefArgMap;
412 if (outRefArgMap.Length != 0)
414 int[] array2 = outRefArgMap;
415 foreach (
int num3
in array2)
417 ValidateReturnArg(outArgs[num3], parameters[num3].ParameterType);
421 int callType = message.GetCallType();
422 if ((callType & 0xF) != 1)
424 Type returnType = reflectionCachedData.ReturnType;
425 if (returnType !=
null)
427 ValidateReturnArg(returnValue, returnType);
430 message.PropagateOutParameters(outArgs, returnValue);
433 private static void ValidateReturnArg(
object arg, Type paramType)
435 if (paramType.IsByRef)
437 paramType = paramType.GetElementType();
439 if (paramType.IsValueType)
443 if (!paramType.IsGenericType || !(paramType.GetGenericTypeDefinition() == typeof(Nullable<>)))
445 throw new RemotingException(Environment.GetResourceString(
"Remoting_Proxy_ReturnValueTypeCannotBeNull"));
448 else if (!paramType.IsInstanceOfType(arg))
450 throw new InvalidCastException(Environment.GetResourceString(
"Remoting_Proxy_BadReturnType"));
453 else if (arg !=
null && !paramType.IsInstanceOfType(arg))
455 throw new InvalidCastException(Environment.GetResourceString(
"Remoting_Proxy_BadReturnType"));
460 internal static IMessage EndInvokeHelper(Message reqMsg,
bool bProxyCase)
464 if (asyncResult ==
null)
466 throw new RemotingException(Environment.GetResourceString(
"Remoting_Message_BadAsyncResult"));
470 throw new InvalidOperationException(Environment.GetResourceString(
"InvalidOperation_MismatchedAsyncResult"));
480 throw new InvalidOperationException(Environment.GetResourceString(
"InvalidOperation_EndInvokeCalledMultiple"));
486 Exception exception = methodReturnMessage.
Exception;
487 if (exception !=
null)
489 throw exception.PrepForRemoting();
491 reqMsg.PropagateOutParameters(methodReturnMessage.
Args, methodReturnMessage.
ReturnValue);
495 result = methodReturnMessage;
534 private void PrivateInvoke(ref MessageData msgData,
int type)
539 RemotingProxy remotingProxy =
null;
542 Message message3 =
new Message();
543 message3.InitFields(msgData);
545 num = message3.GetCallType();
550 remotingProxy = (
this as RemotingProxy);
551 ConstructorCallMessage constructorCallMessage =
null;
553 if (!IsRemotingProxy())
555 constructorCallMessage =
new ConstructorCallMessage(
null,
null,
null, (RuntimeType)
GetProxiedType());
559 constructorCallMessage = remotingProxy.ConstructorMessage;
560 Identity identityObject = remotingProxy.IdentityObject;
561 if (identityObject !=
null)
563 flag = identityObject.IsWellKnown();
566 if ((constructorCallMessage ==
null) | flag)
568 constructorCallMessage =
new ConstructorCallMessage(
null,
null,
null, (RuntimeType)
GetProxiedType());
569 constructorCallMessage.SetFrame(msgData);
570 message = constructorCallMessage;
573 remotingProxy.ConstructorMessage =
null;
574 if (constructorCallMessage.ArgCount != 0)
576 throw new RemotingException(Environment.GetResourceString(
"Remoting_Activation_WellKnownCTOR"));
579 message2 =
new ConstructorReturnMessage((MarshalByRefObject)
GetTransparentProxy(),
null, 0,
null, constructorCallMessage);
583 constructorCallMessage.SetFrame(msgData);
584 message = constructorCallMessage;
588 if (!IsRemotingProxy() && (num & 2) == 2)
591 message2 = EndInvokeHelper(reqMsg, bProxyCase:
true);
593 if (message2 ==
null)
597 logicalCallContext = currentThread.GetMutableExecutionContext().LogicalCallContext;
598 SetCallContextInMessage(message, num, logicalCallContext);
599 logicalCallContext.PropagateOutgoingHeadersToMessage(message);
600 message2 =
Invoke(message);
601 ReturnCallContextToThread(currentThread, message2, num, logicalCallContext);
602 Thread.
CurrentThread.GetMutableExecutionContext().LogicalCallContext.PropagateIncomingHeadersToCallContext(message2);
604 if (!IsRemotingProxy() && (num & 1) == 1)
609 message2 =
new ReturnMessage(asyncResult,
null, 0,
null, message4);
611 HandleReturnMessage(message, message2);
616 MarshalByRefObject marshalByRefObject =
null;
618 if (constructionReturnMessage ==
null)
620 throw new RemotingException(Environment.GetResourceString(
"Remoting_Proxy_BadReturnTypeForActivation"));
622 ConstructorReturnMessage constructorReturnMessage = constructionReturnMessage as ConstructorReturnMessage;
623 if (constructorReturnMessage !=
null)
625 marshalByRefObject = (MarshalByRefObject)constructorReturnMessage.GetObject();
626 if (marshalByRefObject ==
null)
628 throw new RemotingException(Environment.GetResourceString(
"Remoting_Activation_NullReturnValue"));
633 marshalByRefObject = (MarshalByRefObject)RemotingServices.InternalUnmarshal((ObjRef)constructionReturnMessage.
ReturnValue,
GetTransparentProxy(), fRefine:
true);
634 if (marshalByRefObject ==
null)
636 throw new RemotingException(Environment.GetResourceString(
"Remoting_Activation_NullFromInternalUnmarshal"));
641 throw new RemotingException(Environment.GetResourceString(
"Remoting_Activation_InconsistentState"));
643 if (IsRemotingProxy())
645 remotingProxy.ConstructorMessage =
null;
656 message.SetLogicalCallContext(cctx);
660 ((ConstructorCallMessage)reqMsg).SetLogicalCallContext(cctx);
668 if (msgFlags != 0 || retMsg ==
null)
673 if (methodReturnMessage ==
null)
678 if (logicalCallContext ==
null)
680 currentThread.GetMutableExecutionContext().LogicalCallContext = currCtx;
684 if (methodReturnMessage is StackBasedReturnMessage)
688 ExecutionContext mutableExecutionContext = currentThread.GetMutableExecutionContext();
690 mutableExecutionContext.LogicalCallContext = logicalCallContext;
691 if (logicalCallContext2 != logicalCallContext)
693 IPrincipal principal = logicalCallContext2.Principal;
694 if (principal !=
null)
696 logicalCallContext.Principal = principal;
703 internal virtual void Wrap()
705 ServerIdentity serverIdentity = _identity as ServerIdentity;
706 if (serverIdentity !=
null &&
this is RemotingProxy)
708 SetStubData(
this, serverIdentity.ServerContext.InternalContextID);
static Thread CurrentThread
Gets the currently running thread.
Discovers the attributes of a parameter and provides access to parameter metadata.
object ReturnValue
Gets the return value of the method call.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
RealProxy(Type classToProxy, IntPtr stub, object stubData)
Initializes a new instance of the T:System.Runtime.Remoting.Proxies.RealProxy class.
Holds a message returned in response to a method call on a remote object.
RealProxy(Type classToProxy)
Initializes a new instance of the T:System.Runtime.Remoting.Proxies.RealProxy class that represents a...
RealProxy()
Initializes a new instance of the T:System.Runtime.Remoting.Proxies.RealProxy class with default valu...
abstract string FullName
Gets the fully qualified name of the type, including its namespace but not its assembly.
Defines the method call return message interface.
Represents the construction call request of an object.
Defines the basic functionality of a principal object.
static void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
Serializes the specified marshal by reference object into the provided T:System.Runtime....
virtual void GetObjectData(SerializationInfo info, StreamingContext context)
Adds the transparent proxy of the object represented by the current instance of T:System....
bool IsInterface
Gets a value indicating whether the T:System.Type is an interface; that is, not a class or a value ty...
Provides base functionality for proxies.
virtual IMessage GetReplyMessage()
Gets the response message for the asynchronous call.
MarshalByRefObject GetUnwrappedServer()
Returns the server object that is represented by the current proxy instance.
Stores all relevant information required to generate a proxy in order to communicate with a remote ob...
bool IsIn
Gets a value indicating whether this is an input parameter.
void AttachServer(MarshalByRefObject s)
Attaches the current proxy instance to the specified remote T:System.MarshalByRefObject.
static IMethodReturnMessage ExecuteMessage(MarshalByRefObject target, IMethodCallMessage reqMsg)
Connects to the specified remote object, and executes the provided T:System.Runtime....
Describes the source and destination of a given serialized stream, and provides an additional caller-...
virtual bool WaitOne(int millisecondsTimeout, bool exitContext)
Blocks the current thread until the current T:System.Threading.WaitHandle receives a signal,...
virtual bool IsCompleted
Gets a value indicating whether the server has completed the call.
Cer
Specifies a method's behavior when called within a constrained execution region.
Type ActivationType
Gets the type of the remote object to activate.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Identifies a T:System.Runtime.Remoting.Messaging.IMethodReturnMessage that is returned after attempti...
Provides information about, and means to manipulate, the current environment and platform....
Represents a globally unique identifier (GUID).To browse the .NET Framework source code for this type...
Manages the execution context for the current thread. This class cannot be inherited.
Encapsulates the results of an asynchronous operation on a delegate.
static object GetStubData(RealProxy rp)
Retrieves stub data that is stored for the specified proxy.
LogicalCallContext LogicalCallContext
Gets the T:System.Runtime.Remoting.Messaging.LogicalCallContext for the current method call.
object [] OutArgs
Returns the specified argument marked as a ref or an out parameter.
A platform-specific type that is used to represent a pointer or a handle.
object [] Args
Gets an array of arguments passed to the method.
virtual IntPtr GetCOMIUnknown(bool fIsMarshalled)
Requests an unmanaged reference to the object represented by the current proxy instance.
Provides static methods to aid with remoting channel registration, resolution, and URL discovery....
Represents type declarations: class types, interface types, array types, value types,...
Provides information about methods and constructors.
Provides a way to access a managed object from unmanaged memory.
MethodImplOptions
Defines the details of how a method is implemented.
static void SetStubData(RealProxy rp, object stubData)
Sets the stub data for the specified proxy.
Indicates that data in the pipe is transmitted and read as a stream of messages.
virtual object GetTransparentProxy()
Returns the transparent proxy for the current instance of T:System.Runtime.Remoting....
Provides a set of properties that are carried with the execution code path during remote method calls...
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
virtual IMessage SyncProcessMessage(IMessage msg)
Synchronously processes a response message returned by a method call on a remote object.
Contains communication data sent between cooperating message sinks.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
The exception that is thrown when one of the arguments provided to a method is not valid.
virtual WaitHandle AsyncWaitHandle
Gets a T:System.Threading.WaitHandle that encapsulates Win32 synchronization handles,...
virtual IntPtr SupportsInterface(ref Guid iid)
Requests a COM interface with the specified ID.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
bool IsMarshalByRef
Gets a value indicating whether the T:System.Type is marshaled by reference.
bool IsOut
Gets a value indicating whether this is an output parameter.
virtual object AsyncDelegate
Gets the delegate object on which the asynchronous call was invoked.
virtual Type ParameterType
Gets the Type of this parameter.
abstract IMessage Invoke(IMessage msg)
When overridden in a derived class, invokes the method that is specified in the provided T:System....
Consistency
Specifies a reliability contract.
bool EndInvokeCalled
Gets or sets a value indicating whether EndInvoke has been called on the current T:System....
virtual void SetCOMIUnknown(IntPtr i)
Stores an unmanaged proxy of the object that is represented by the current instance.
Provides information about a specific culture (called a locale for unmanaged code development)....
bool IsByRef
Gets a value indicating whether the T:System.Type is passed by reference.
SecurityPermissionFlag
Specifies access flags for the security permission object.
Provides several methods for using and publishing remoted objects and proxies. This class cannot be i...
Type GetProxiedType()
Returns the T:System.Type of the object that the current instance of T:System.Runtime....
IConstructionReturnMessage InitializeServerObject(IConstructionCallMessage ctorMsg)
Initializes a new instance of the object T:System.Type of the remote object that the current instance...
static Context CurrentContext
Gets the current context in which the thread is executing.
The exception that is thrown when something has gone wrong during remoting.
MarshalByRefObject DetachServer()
Detaches the current proxy instance from the remote server object that it represents.
Exception Exception
Gets the exception thrown during the method call.
virtual ObjRef CreateObjRef(Type requestedType)
Creates an T:System.Runtime.Remoting.ObjRef for the specified object type, and registers it with the ...
Enables access to objects across application domain boundaries in applications that support remoting.
Creates and controls a thread, sets its priority, and gets its status.