3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 /*============================================================
11 ** Purpose: Defines the message object created by the transparent
12 ** proxy and used by the message sinks
15 ===========================================================*/
16 namespace System.Runtime.Remoting.Messaging {
18 using System.Collections;
19 using System.Threading;
20 using System.Runtime.InteropServices;
21 using System.Runtime.Remoting;
22 using System.Runtime.Remoting.Activation;
23 using System.Runtime.Remoting.Contexts;
24 using System.Runtime.Remoting.Channels;
25 using System.Runtime.Remoting.Metadata;
26 using System.Runtime.Remoting.Metadata.W3cXsd2001;
27 using System.Runtime.Remoting.Proxies;
28 using System.Runtime.Serialization;
29 using System.Runtime.Serialization.Formatters;
30 using System.Runtime.Serialization.Formatters.Binary;
31 using System.Runtime.Versioning;
32 using System.Reflection;
34 using System.Runtime.CompilerServices;
35 using System.Security.Permissions;
36 using System.Globalization;
37 using System.Diagnostics.Contracts;
38 using System.Security;
40 //+=======================================================================
42 // Synopsis: Message is used to represent call and is created by the
45 //-=======================================================================
47 internal class Message : IMethodCallMessage, IInternalMessage, ISerializable
51 // Keep these in sync with the flags in Message.h
53 internal const int Sync = 0; // Synchronous call
54 internal const int BeginAsync = 1; // Async Begin call
55 internal const int EndAsync = 2; // Async End call
56 internal const int Ctor = 4; // The call is a .Ctor
57 internal const int OneWay = 8; // One way call
58 internal const int CallMask = 15; // Mask for call type bits
60 internal const int FixedArgs = 16; // Fixed number of arguments call
61 internal const int VarArgs = 32; // Variable number of arguments call
64 // Changing the type or position of these fields requires making changes
65 // to the corresponding unmanaged class and to mscorlib.h
68 // Private data members
69 private String _MethodName; // Method name
70 private Type[] _MethodSignature; // Array of parameter types
71 private MethodBase _MethodBase; // Reflection method object
72 private Object _properties; // hash table for properities
73 private String _URI; // target object URI
74 private String _typeName;
75 private Exception _Fault; // null if no fault
77 private Identity _ID; // identity cached during Invoke
78 private ServerIdentity _srvID; // server Identity cached during Invoke
79 private ArgMapper _argMapper;
80 [System.Security.SecurityCritical] // auto-generated
81 private LogicalCallContext _callContext;
83 private IntPtr _frame; // ptr to the call frame
84 private IntPtr _methodDesc; // ptr to the internal method descriptor
85 private IntPtr _metaSigHolder; // Pointer to the MetaSig structure
86 private IntPtr _delegateMD; // ptr to the internal method descriptor for the delegate
87 private IntPtr _governingType; // ptr to the internal type handle for the type calling the method
89 private int _flags; // internal flags
90 private bool _initDone; // called the native init routine
93 internal static String CallContextKey = "__CallContext";
94 internal static String UriKey = "__Uri";
97 public virtual Exception GetFault() {return _Fault;}
98 public virtual void SetFault(Exception e) {_Fault = e;}
100 internal virtual void SetOneWay() { _flags |= Message.OneWay;}
101 public virtual int GetCallType()
103 // We should call init only if neccessary
108 internal IntPtr GetFramePtr() { return _frame;}
112 [System.Security.SecurityCritical] // auto-generated
113 [ResourceExposure(ResourceScope.None)]
114 [MethodImplAttribute(MethodImplOptions.InternalCall)]
115 public extern void GetAsyncBeginInfo(out AsyncCallback acbd,
118 [System.Security.SecurityCritical] // auto-generated
119 [ResourceExposure(ResourceScope.None)]
120 [MethodImplAttribute(MethodImplOptions.InternalCall)]
121 public extern Object GetThisPtr();
122 [System.Security.SecurityCritical] // auto-generated
123 [ResourceExposure(ResourceScope.None)]
124 [MethodImplAttribute(MethodImplOptions.InternalCall)]
125 public extern IAsyncResult GetAsyncResult();
129 // This method no longer does any meaninfull work, however it is
130 // publicly exposed so we cannot get rid of it.
133 [System.Security.SecurityCritical] // auto-generated
134 [ResourceExposure(ResourceScope.None)]
135 [MethodImplAttribute(MethodImplOptions.InternalCall)]
136 public extern Object GetReturnValue();
139 // This should be internal. The message object is
140 // allocated and deallocated via a pool to enable
147 // NOTE: This method is called multiple times as we reuse the
148 // message object. Make sure that you reset any fields that you
149 // add to the message object to the default values. This will
150 // ensure that the reused message object starts with the correct
152 [System.Security.SecurityCritical] // auto-generated
153 internal void InitFields(MessageData msgData)
155 _frame = msgData.pFrame;
156 _delegateMD = msgData.pDelegateMD;
157 _methodDesc = msgData.pMethodDesc;
158 _flags = msgData.iFlags;
160 _metaSigHolder = msgData.pSig;
161 _governingType = msgData.thGoverningType;
164 _MethodSignature = null;
172 if (_properties != null)
174 // A dictionary object already exists. This case occurs
175 // when we reuse the message object. Just remove all the
176 // entries from the dictionary object and reuse it.
177 ((IDictionary)_properties).Clear();
182 private void InitIfNecessary()
186 // We assume that Init is an idempotent operation
193 //-------------------------------------------------------------------
195 //-------------------------------------------------------------------
196 ServerIdentity IInternalMessage.ServerIdentityObject
198 [System.Security.SecurityCritical]
199 get { return _srvID; }
200 [System.Security.SecurityCritical]
201 set {_srvID = value;}
204 Identity IInternalMessage.IdentityObject
206 [System.Security.SecurityCritical]
208 [System.Security.SecurityCritical]
212 [System.Security.SecurityCritical]
213 void IInternalMessage.SetURI(String URI)
218 [System.Security.SecurityCritical]
219 void IInternalMessage.SetCallContext(LogicalCallContext callContext)
221 _callContext = callContext;
224 [System.Security.SecurityCritical]
225 bool IInternalMessage.HasProperties()
227 return _properties != null;
230 //-------------------------------------------------------------------
232 //-------------------------------------------------------------------
233 public IDictionary Properties
235 [System.Security.SecurityCritical] // auto-generated
238 if (_properties == null)
240 Interlocked.CompareExchange(ref _properties,
241 new MCMDictionary(this, null),
244 return (IDictionary)_properties;
248 //-------------------------------------------------------------------
249 // IMethodCallMessage
250 //-------------------------------------------------------------------
254 [System.Security.SecurityCritical] // auto-generated
257 set { _URI = value; }
260 public bool HasVarArgs
262 [System.Security.SecurityCritical] // auto-generated
265 // When this method is called for the first time, we
266 // obtain the answer from a native call and set the flags
267 if((0 == (_flags & Message.FixedArgs)) &&
268 (0 == (_flags & Message.VarArgs)))
270 if(!InternalHasVarArgs())
272 _flags |= Message.FixedArgs;
276 _flags |= Message.VarArgs;
279 return (1 == (_flags & Message.VarArgs));
286 [System.Security.SecurityCritical] // auto-generated
287 get { return InternalGetArgCount();}
290 [System.Security.SecurityCritical] // auto-generated
291 public Object GetArg(int argNum)
293 return InternalGetArg(argNum);
296 [System.Security.SecurityCritical] // auto-generated
297 public String GetArgName(int index)
299 if (index >= ArgCount)
301 throw new ArgumentOutOfRangeException("index");
303 Contract.EndContractBlock();
305 RemotingMethodCachedData methodCache =
306 InternalRemotingServices.GetReflectionCachedData(GetMethodBase());
308 ParameterInfo[] pi = methodCache.Parameters;
310 if (index < pi.Length)
312 return pi[index].Name;
316 return "VarArg" + (index - pi.Length);
322 [System.Security.SecurityCritical] // auto-generated
325 return InternalGetArgs();
329 public int InArgCount
331 [System.Security.SecurityCritical] // auto-generated
334 if (_argMapper == null) _argMapper = new ArgMapper(this, false);
335 return _argMapper.ArgCount;
339 [System.Security.SecurityCritical] // auto-generated
340 public Object GetInArg(int argNum)
342 if (_argMapper == null) _argMapper = new ArgMapper(this, false);
343 return _argMapper.GetArg(argNum);
346 [System.Security.SecurityCritical] // auto-generated
347 public String GetInArgName(int index)
349 if (_argMapper == null) _argMapper = new ArgMapper(this, false);
350 return _argMapper.GetArgName(index);
353 public Object[] InArgs
355 [System.Security.SecurityCritical] // auto-generated
358 if (_argMapper == null) _argMapper = new ArgMapper(this, false);
359 return _argMapper.Args;
363 [System.Security.SecurityCritical] // auto-generated
364 private void UpdateNames()
366 RemotingMethodCachedData methCache =
367 InternalRemotingServices.GetReflectionCachedData(GetMethodBase());
368 _typeName = methCache.TypeAndAssemblyName;
369 _MethodName = methCache.MethodName;
372 public String MethodName
374 [System.Security.SecurityCritical] // auto-generated
377 if(null == _MethodName)
383 public String TypeName
385 [System.Security.SecurityCritical] // auto-generated
388 if (_typeName == null)
394 public Object MethodSignature
396 [System.Security.SecurityCritical] // auto-generated
399 if(null == _MethodSignature)
400 _MethodSignature = GenerateMethodSignature(GetMethodBase());
402 return _MethodSignature;
406 public LogicalCallContext LogicalCallContext
408 [System.Security.SecurityCritical] // auto-generated
411 return GetLogicalCallContext();
415 public MethodBase MethodBase
417 [System.Security.SecurityCritical] // auto-generated
420 return GetMethodBase();
428 [System.Security.SecurityCritical] // auto-generated_required
429 public void GetObjectData(SerializationInfo info, StreamingContext context)
431 throw new NotSupportedException(
432 Environment.GetResourceString("NotSupported_Method"));
435 [System.Security.SecurityCritical] // auto-generated
436 internal MethodBase GetMethodBase()
438 if(null == _MethodBase)
442 IRuntimeMethodInfo mh = new RuntimeMethodInfoStub(_methodDesc, null);
443 _MethodBase = RuntimeType.GetMethodBase(Type.GetTypeFromHandleUnsafe(_governingType), mh);
449 [System.Security.SecurityCritical] // auto-generated
450 internal LogicalCallContext SetLogicalCallContext(
451 LogicalCallContext callCtx)
453 LogicalCallContext oldCtx = _callContext;
454 _callContext = callCtx;
459 [System.Security.SecurityCritical] // auto-generated
460 internal LogicalCallContext GetLogicalCallContext()
462 if (_callContext == null)
463 _callContext = new LogicalCallContext();
468 // Internal helper to create method signature
469 [System.Security.SecurityCritical] // auto-generated
470 internal static Type[] GenerateMethodSignature(MethodBase mb)
472 RemotingMethodCachedData methodCache =
473 InternalRemotingServices.GetReflectionCachedData(mb);
475 ParameterInfo[] paramArray = methodCache.Parameters;
476 Type[] methodSig = new Type[paramArray.Length];
477 for(int i = 0; i < paramArray.Length; i++)
479 methodSig[i] = paramArray[i].ParameterType;
483 } // GenerateMethodSignature
486 // The following two routines are used by StackBuilderSink to check
487 // the consistency of arguments.
489 // Check that all the arguments are of the type
490 // specified by the parameter list.
492 [System.Security.SecurityCritical] // auto-generated
493 internal static Object[] CoerceArgs(IMethodMessage m)
495 MethodBase mb = m.MethodBase;
496 Contract.Assert(mb != null, "null method base passed to CoerceArgs");
498 RemotingMethodCachedData methodCache = InternalRemotingServices.GetReflectionCachedData(mb);
500 return CoerceArgs(m, methodCache.Parameters);
503 [System.Security.SecurityCritical] // auto-generated
504 internal static Object[] CoerceArgs(IMethodMessage m, ParameterInfo[] pi)
506 return CoerceArgs(m.MethodBase, m.Args, pi);
509 [System.Security.SecurityCritical] // auto-generated
510 internal static Object[] CoerceArgs(MethodBase mb, Object[] args, ParameterInfo[] pi)
514 throw new ArgumentNullException("pi");
516 Contract.EndContractBlock();
518 if (pi.Length != args.Length)
520 throw new RemotingException(
522 CultureInfo.CurrentCulture, Environment.GetResourceString(
523 "Remoting_Message_ArgMismatch"),
524 mb.DeclaringType.FullName, mb.Name,
525 args.Length, pi.Length));
528 for (int i=0; i < pi.Length; i++)
530 ParameterInfo currentPi = pi[i];
531 Type pt = currentPi.ParameterType;
532 Object oArg = args[i];
535 args[i] = CoerceArg(oArg, pt);
541 Type paramType = pt.GetElementType();
542 if (paramType.IsValueType)
544 // nullables can be null,
547 // we need to fill in the blanks for value types if they are null
548 args[i] = Activator.CreateInstance(paramType, true);
552 if (!(paramType.IsGenericType && paramType.GetGenericTypeDefinition() == typeof(Nullable<>)))
554 throw new RemotingException(
556 CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_MissingArgValue"),
557 paramType.FullName, i));
566 // nullables can be null,
567 if (!(pt.IsGenericType && pt.GetGenericTypeDefinition() == typeof(Nullable<>)))
569 // A null value was passed as a value type parameter.
570 throw new RemotingException(
572 CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Message_MissingArgValue"),
584 [System.Security.SecurityCritical] // auto-generated
585 internal static Object CoerceArg(Object value, Type pt)
591 Exception inner = null;
596 pt = pt.GetElementType();
599 if (pt.IsInstanceOfType(value))
605 ret = Convert.ChangeType(value, pt, CultureInfo.InvariantCulture);
610 // Quietly ignore all exceptions. We will throw
611 // a more meaningful exception below.
615 // If the coercion failed then throw an exception
618 // NOTE: Do not call value.ToString() on proxies as
619 // it results in loading the type and loss of refinement
620 // optimization or denial of service attacks by loading
621 // a lot of types in the server.
622 String valueName = null;
623 if(RemotingServices.IsTransparentProxy(value))
625 valueName = typeof(MarshalByRefObject).ToString();
629 valueName = value.ToString();
632 throw new RemotingException(
634 CultureInfo.CurrentCulture, Environment.GetResourceString(
635 "Remoting_Message_CoercionFailed"), valueName, pt), inner);
642 [System.Security.SecurityCritical] // auto-generated
643 internal static Object SoapCoerceArg(Object value, Type pt, Hashtable keyToNamespaceTable)
653 pt = pt.GetElementType();
656 if (pt.IsInstanceOfType(value))
662 String strValue = value as String;
663 if (strValue != null)
665 if (pt == typeof(Double))
667 if (strValue == "INF")
668 ret = Double.PositiveInfinity;
669 else if (strValue == "-INF")
670 ret = Double.NegativeInfinity;
672 ret = Double.Parse(strValue, CultureInfo.InvariantCulture);
674 else if (pt == typeof(Single))
676 if (strValue == "INF")
677 ret = Single.PositiveInfinity;
678 else if (strValue == "-INF")
679 ret = Single.NegativeInfinity;
681 ret = Single.Parse(strValue, CultureInfo.InvariantCulture);
683 else if (SoapType.typeofISoapXsd.IsAssignableFrom(pt))
685 if (pt == SoapType.typeofSoapTime)
686 ret = SoapTime.Parse(strValue);
687 else if (pt == SoapType.typeofSoapDate)
688 ret = SoapDate.Parse(strValue);
689 else if (pt == SoapType.typeofSoapYearMonth)
690 ret = SoapYearMonth.Parse(strValue);
691 else if (pt == SoapType.typeofSoapYear)
692 ret = SoapYear.Parse(strValue);
693 else if (pt == SoapType.typeofSoapMonthDay)
694 ret = SoapMonthDay.Parse(strValue);
695 else if (pt == SoapType.typeofSoapDay)
696 ret = SoapDay.Parse(strValue);
697 else if (pt == SoapType.typeofSoapMonth)
698 ret = SoapMonth.Parse(strValue);
699 else if (pt == SoapType.typeofSoapHexBinary)
700 ret = SoapHexBinary.Parse(strValue);
701 else if (pt == SoapType.typeofSoapBase64Binary)
702 ret = SoapBase64Binary.Parse(strValue);
703 else if (pt == SoapType.typeofSoapInteger)
704 ret = SoapInteger.Parse(strValue);
705 else if (pt == SoapType.typeofSoapPositiveInteger)
706 ret = SoapPositiveInteger.Parse(strValue);
707 else if (pt == SoapType.typeofSoapNonPositiveInteger)
708 ret = SoapNonPositiveInteger.Parse(strValue);
709 else if (pt == SoapType.typeofSoapNonNegativeInteger)
710 ret = SoapNonNegativeInteger.Parse(strValue);
711 else if (pt == SoapType.typeofSoapNegativeInteger)
712 ret = SoapNegativeInteger.Parse(strValue);
713 else if (pt == SoapType.typeofSoapAnyUri)
714 ret = SoapAnyUri.Parse(strValue);
715 else if (pt == SoapType.typeofSoapQName)
717 ret = SoapQName.Parse(strValue);
718 SoapQName soapQName = (SoapQName)ret;
719 if (soapQName.Key.Length == 0)
720 soapQName.Namespace = (String)keyToNamespaceTable["xmlns"];
722 soapQName.Namespace = (String)keyToNamespaceTable["xmlns"+":"+soapQName.Key];
724 else if (pt == SoapType.typeofSoapNotation)
725 ret = SoapNotation.Parse(strValue);
726 else if (pt == SoapType.typeofSoapNormalizedString)
727 ret = SoapNormalizedString.Parse(strValue);
728 else if (pt == SoapType.typeofSoapToken)
729 ret = SoapToken.Parse(strValue);
730 else if (pt == SoapType.typeofSoapLanguage)
731 ret = SoapLanguage.Parse(strValue);
732 else if (pt == SoapType.typeofSoapName)
733 ret = SoapName.Parse(strValue);
734 else if (pt == SoapType.typeofSoapIdrefs)
735 ret = SoapIdrefs.Parse(strValue);
736 else if (pt == SoapType.typeofSoapEntities)
737 ret = SoapEntities.Parse(strValue);
738 else if (pt == SoapType.typeofSoapNmtoken)
739 ret = SoapNmtoken.Parse(strValue);
740 else if (pt == SoapType.typeofSoapNmtokens)
741 ret = SoapNmtokens.Parse(strValue);
742 else if (pt == SoapType.typeofSoapNcName)
743 ret = SoapNcName.Parse(strValue);
744 else if (pt == SoapType.typeofSoapId)
745 ret = SoapId.Parse(strValue);
746 else if (pt == SoapType.typeofSoapIdref)
747 ret = SoapIdref.Parse(strValue);
748 else if (pt == SoapType.typeofSoapEntity)
749 ret = SoapEntity.Parse(strValue);
751 else if (pt == typeof(Boolean))
753 if (strValue == "1" || strValue == "true")
755 else if (strValue == "0" || strValue =="false")
759 throw new RemotingException(
761 CultureInfo.CurrentCulture, Environment.GetResourceString(
762 "Remoting_Message_CoercionFailed"), strValue, pt));
765 else if (pt == typeof(DateTime))
766 ret = SoapDateTime.Parse(strValue);
767 else if (pt.IsPrimitive)
768 ret = Convert.ChangeType(value, pt, CultureInfo.InvariantCulture);
769 else if (pt == typeof(TimeSpan))
770 ret = SoapDuration.Parse(strValue);
771 else if (pt == typeof(Char))
775 ret = Convert.ChangeType(value, pt, CultureInfo.InvariantCulture); //Should this just throw an exception
778 ret = Convert.ChangeType(value, pt, CultureInfo.InvariantCulture);
783 // Quietly ignore all exceptions. We will throw
784 // a more meaningful exception below.
787 // If the coercion failed then throw an exception
790 // NOTE: Do not call value.ToString() on proxies as
791 // it results in loading the type and loss of refinement
792 // optimization or denial of service attacks by loading
793 // a lot of types in the server.
794 String valueName = null;
795 if(RemotingServices.IsTransparentProxy(value))
797 valueName = typeof(MarshalByRefObject).ToString();
801 valueName = value.ToString();
804 throw new RemotingException(
806 CultureInfo.CurrentCulture, Environment.GetResourceString(
807 "Remoting_Message_CoercionFailed"), valueName, pt));
812 }//end of SoapCoerceArg
815 [System.Security.SecurityCritical] // auto-generated
816 [ResourceExposure(ResourceScope.None)]
817 [MethodImplAttribute(MethodImplOptions.InternalCall)]
818 internal extern bool InternalHasVarArgs();
820 [System.Security.SecurityCritical] // auto-generated
821 [ResourceExposure(ResourceScope.None)]
822 [MethodImplAttribute(MethodImplOptions.InternalCall)]
823 internal extern int InternalGetArgCount();
825 [System.Security.SecurityCritical] // auto-generated
826 [ResourceExposure(ResourceScope.None)]
827 [MethodImplAttribute(MethodImplOptions.InternalCall)]
828 private extern Object InternalGetArg(int argNum);
830 [System.Security.SecurityCritical] // auto-generated
831 [ResourceExposure(ResourceScope.None)]
832 [MethodImplAttribute(MethodImplOptions.InternalCall)]
833 private extern Object[] InternalGetArgs();
835 [System.Security.SecurityCritical] // auto-generated
836 [ResourceExposure(ResourceScope.None)]
837 [MethodImplAttribute(MethodImplOptions.InternalCall)]
838 public extern void PropagateOutParameters(Object[] OutArgs, Object retVal);
840 [System.Security.SecurityCritical] // auto-generated
841 [ResourceExposure(ResourceScope.None)]
842 [MethodImplAttribute(MethodImplOptions.InternalCall)]
843 public extern bool Dispatch(Object target);
848 [System.Security.SecurityCritical] // auto-generated
849 [System.Diagnostics.Conditional("_REMOTING_DEBUG")]
850 public static void DebugOut(String s)
853 "REMOTE", "RMTING: Thrd "
854 + Thread.CurrentThread.GetHashCode()
856 OutToUnmanagedDebugger(
858 + Thread.CurrentThread.GetHashCode()
862 [System.Security.SecurityCritical] // auto-generated
863 [ResourceExposure(ResourceScope.None)]
864 [MethodImplAttribute(MethodImplOptions.InternalCall)]
865 internal extern static void OutToUnmanagedDebugger(String s);
867 [System.Security.SecurityCritical] // auto-generated
868 internal static LogicalCallContext PropagateCallContextFromMessageToThread(IMessage msg)
870 return CallContext.SetLogicalCallContext(
871 (LogicalCallContext) msg.Properties[Message.CallContextKey]);
874 [System.Security.SecurityCritical] // auto-generated
875 internal static void PropagateCallContextFromThreadToMessage(IMessage msg)
877 LogicalCallContext callCtx = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
879 msg.Properties[Message.CallContextKey] = callCtx;
882 [System.Security.SecurityCritical] // auto-generated
883 internal static void PropagateCallContextFromThreadToMessage(IMessage msg, LogicalCallContext oldcctx)
885 // First do the common work
886 PropagateCallContextFromThreadToMessage(msg);
888 // restore the old call context on the thread
889 CallContext.SetLogicalCallContext(oldcctx);
893 //+================================================================================
895 // Synopsis: Return message for constructors
897 //-================================================================================
898 [System.Security.SecurityCritical] // auto-generated
899 internal class ConstructorReturnMessage : ReturnMessage, IConstructionReturnMessage
902 private const int Intercept = 0x1;
904 private MarshalByRefObject _o;
908 public ConstructorReturnMessage(MarshalByRefObject o, Object[] outArgs, int outArgsCount,
909 LogicalCallContext callCtx, IConstructionCallMessage ccm)
910 : base(o, outArgs, outArgsCount, callCtx, ccm)
916 public ConstructorReturnMessage(Exception e, IConstructionCallMessage ccm)
921 public override Object ReturnValue
923 [System.Security.SecurityCritical]
926 if (_iFlags == Intercept)
928 return RemotingServices.MarshalInternal(_o,null,null);
932 return base.ReturnValue;
938 public override IDictionary Properties
940 [System.Security.SecurityCritical]
943 if (_properties == null)
945 Object properties = new CRMDictionary(this, new Hashtable());
946 Interlocked.CompareExchange(ref _properties, properties, null);
948 return(IDictionary) _properties;
952 internal Object GetObject()
958 //+========================================================================
960 // Synopsis: client side implementation of activation message
962 //-========================================================================
963 internal class ConstructorCallMessage : IConstructionCallMessage
968 private Object[] _callSiteActivationAttributes;
969 private Object[] _womGlobalAttributes;
970 private Object[] _typeAttributes;
972 // The activation type isn't serialized because we want to
973 // re-resolve the activation type name on the other side
974 // based on _activationTypeName.
976 private RuntimeType _activationType;
978 private String _activationTypeName;
980 private IList _contextProperties;
982 private Message _message;
983 private Object _properties;
984 private ArgMapper _argMapper;
985 private IActivator _activator;
988 private const int CCM_ACTIVATEINCONTEXT = 0x01;
990 private ConstructorCallMessage()
992 // Default constructor
995 [System.Security.SecurityCritical] // auto-generated
996 internal ConstructorCallMessage(Object[] callSiteActivationAttributes,
997 Object[]womAttr, Object[] typeAttr, RuntimeType serverType)
999 _activationType = serverType;
1000 _activationTypeName = RemotingServices.GetDefaultQualifiedTypeName(_activationType);
1001 _callSiteActivationAttributes = callSiteActivationAttributes;
1002 _womGlobalAttributes = womAttr;
1003 _typeAttributes = typeAttr;
1006 [System.Security.SecurityCritical] // auto-generated
1007 public Object GetThisPtr()
1009 if (_message != null)
1011 return _message.GetThisPtr();
1015 throw new InvalidOperationException(
1016 Environment.GetResourceString(
1017 "InvalidOperation_InternalState"));
1021 public Object[] CallSiteActivationAttributes
1023 [System.Security.SecurityCritical] // auto-generated
1026 return _callSiteActivationAttributes;
1031 internal Object[] GetWOMAttributes()
1033 return _womGlobalAttributes;
1036 internal Object[] GetTypeAttributes()
1038 return _typeAttributes;
1041 public Type ActivationType
1043 [System.Security.SecurityCritical] // auto-generated
1046 if ((_activationType == null) && (_activationTypeName != null))
1047 _activationType = RemotingServices.InternalGetTypeFromQualifiedTypeName(_activationTypeName, false);
1049 return _activationType;
1053 public String ActivationTypeName
1055 [System.Security.SecurityCritical] // auto-generated
1058 return _activationTypeName;
1062 public IList ContextProperties
1064 [System.Security.SecurityCritical] // auto-generated
1067 if (_contextProperties == null)
1069 _contextProperties = new ArrayList();
1071 return _contextProperties;
1077 [System.Security.SecurityCritical] // auto-generated
1080 if (_message != null)
1082 return _message.Uri;
1086 throw new InvalidOperationException(
1087 Environment.GetResourceString(
1088 "InvalidOperation_InternalState"));
1094 if (_message != null)
1096 _message.Uri = value;
1100 throw new InvalidOperationException(
1101 Environment.GetResourceString(
1102 "InvalidOperation_InternalState"));
1108 public String MethodName
1110 [System.Security.SecurityCritical] // auto-generated
1113 if (_message != null)
1115 return _message.MethodName;
1119 throw new InvalidOperationException(
1120 Environment.GetResourceString(
1121 "InvalidOperation_InternalState"));
1126 public String TypeName
1128 [System.Security.SecurityCritical] // auto-generated
1131 if (_message != null)
1133 return _message.TypeName;
1137 throw new InvalidOperationException(
1138 Environment.GetResourceString(
1139 "InvalidOperation_InternalState"));
1144 public Object MethodSignature
1146 [System.Security.SecurityCritical] // auto-generated
1149 if (_message != null)
1151 return _message.MethodSignature;
1155 throw new InvalidOperationException(
1156 Environment.GetResourceString(
1157 "InvalidOperation_InternalState"));
1160 } // MethodSignature
1162 public MethodBase MethodBase
1164 [System.Security.SecurityCritical] // auto-generated
1167 if (_message != null)
1169 return _message.MethodBase;
1173 throw new InvalidOperationException(
1174 Environment.GetResourceString(
1175 "InvalidOperation_InternalState"));
1182 public int InArgCount
1184 [System.Security.SecurityCritical] // auto-generated
1187 if (_argMapper == null)
1188 _argMapper = new ArgMapper(this, false);
1189 return _argMapper.ArgCount;
1193 [System.Security.SecurityCritical] // auto-generated
1194 public Object GetInArg(int argNum)
1196 if (_argMapper == null)
1197 _argMapper = new ArgMapper(this, false);
1198 return _argMapper.GetArg(argNum);
1202 [System.Security.SecurityCritical] // auto-generated
1203 public String GetInArgName(int index)
1205 if (_argMapper == null)
1206 _argMapper = new ArgMapper(this, false);
1207 return _argMapper.GetArgName(index);
1209 public Object[] InArgs
1211 [System.Security.SecurityCritical] // auto-generated
1214 if (_argMapper == null)
1215 _argMapper = new ArgMapper(this, false);
1216 return _argMapper.Args;
1222 [System.Security.SecurityCritical] // auto-generated
1225 if (_message != null)
1227 return _message.ArgCount;
1231 throw new InvalidOperationException(
1232 Environment.GetResourceString(
1233 "InvalidOperation_InternalState"));
1238 [System.Security.SecurityCritical] // auto-generated
1239 public Object GetArg(int argNum)
1241 if (_message != null)
1243 return _message.GetArg(argNum);
1247 throw new InvalidOperationException(
1248 Environment.GetResourceString(
1249 "InvalidOperation_InternalState"));
1253 [System.Security.SecurityCritical] // auto-generated
1254 public String GetArgName(int index)
1256 if (_message != null)
1258 return _message.GetArgName(index);
1262 throw new InvalidOperationException(
1263 Environment.GetResourceString(
1264 "InvalidOperation_InternalState"));
1268 public bool HasVarArgs
1270 [System.Security.SecurityCritical] // auto-generated
1273 if (_message != null)
1275 return _message.HasVarArgs;
1279 throw new InvalidOperationException(
1280 Environment.GetResourceString(
1281 "InvalidOperation_InternalState"));
1286 public Object[] Args
1288 [System.Security.SecurityCritical] // auto-generated
1291 if (_message != null)
1293 return _message.Args;
1297 throw new InvalidOperationException(
1298 Environment.GetResourceString(
1299 "InvalidOperation_InternalState"));
1304 public IDictionary Properties
1306 [System.Security.SecurityCritical] // auto-generated
1309 if (_properties == null)
1311 Object properties = new CCMDictionary(this, new Hashtable());
1312 Interlocked.CompareExchange(ref _properties, properties, null);
1314 return(IDictionary) _properties;
1318 public IActivator Activator
1320 [System.Security.SecurityCritical] // auto-generated
1321 get { return _activator; }
1322 [System.Security.SecurityCritical] // auto-generated
1323 set { _activator = value; }
1326 public LogicalCallContext LogicalCallContext
1328 [System.Security.SecurityCritical] // auto-generated
1331 return GetLogicalCallContext();
1336 internal bool ActivateInContext
1338 get { return((_iFlags & CCM_ACTIVATEINCONTEXT) != 0);}
1339 set { _iFlags = value ? (_iFlags | CCM_ACTIVATEINCONTEXT) : (_iFlags & ~CCM_ACTIVATEINCONTEXT);}
1342 [System.Security.SecurityCritical] // auto-generated
1343 internal void SetFrame(MessageData msgData)
1345 Contract.Assert(_message == null, "Can't set frame twice on ConstructorCallMessage");
1346 _message = new Message();
1347 _message.InitFields(msgData);
1350 [System.Security.SecurityCritical] // auto-generated
1351 internal LogicalCallContext GetLogicalCallContext()
1353 if (_message != null)
1355 return _message.GetLogicalCallContext();
1359 throw new InvalidOperationException(
1360 Environment.GetResourceString(
1361 "InvalidOperation_InternalState"));
1365 [System.Security.SecurityCritical] // auto-generated
1366 internal LogicalCallContext SetLogicalCallContext(LogicalCallContext ctx)
1368 if (_message != null)
1370 return _message.SetLogicalCallContext(ctx);
1374 throw new InvalidOperationException(
1375 Environment.GetResourceString(
1376 "InvalidOperation_InternalState"));
1381 internal Message GetMessage()
1387 //+========================================================================
1389 // Synopsis: Specialization of MessageDictionary for
1390 // ConstructorCallMessage objects
1392 //-========================================================================
1394 internal class CCMDictionary : MessageDictionary
1396 public static String[] CCMkeys = {
1399 "__MethodSignature", //2
1402 "__CallContext", //5
1403 "__CallSiteActivationAttributes", //6
1404 "__ActivationType", //7
1405 "__ContextProperties", //8
1407 "__ActivationTypeName"}; //10
1409 internal IConstructionCallMessage _ccmsg; // back pointer to message object
1412 public CCMDictionary(IConstructionCallMessage msg, IDictionary idict)
1413 : base(CCMkeys, idict)
1418 [System.Security.SecuritySafeCritical] // auto-generated
1419 internal override Object GetMessageValue(int i)
1426 return _ccmsg.MethodName;
1428 return _ccmsg.MethodSignature;
1430 return _ccmsg.TypeName;
1434 return FetchLogicalCallContext();
1436 return _ccmsg.CallSiteActivationAttributes;
1438 // This it to keep us from serializing the requested server type
1441 return _ccmsg.ContextProperties;
1443 return _ccmsg.Activator;
1445 return _ccmsg.ActivationTypeName;
1447 // We should not get here!
1448 throw new RemotingException(
1449 Environment.GetResourceString(
1450 "Remoting_Default"));
1453 [System.Security.SecurityCritical] // auto-generated
1454 private LogicalCallContext FetchLogicalCallContext()
1456 ConstructorCallMessage ccm = _ccmsg as ConstructorCallMessage;
1459 return ccm.GetLogicalCallContext();
1461 else if (_ccmsg is ConstructionCall)
1463 // This is the case where the message got serialized
1465 return((MethodCall)_ccmsg).GetLogicalCallContext();
1469 throw new RemotingException(
1470 Environment.GetResourceString(
1471 "Remoting_Message_BadType"));
1475 [System.Security.SecurityCritical]
1476 internal override void SetSpecialKey(int keyNum, Object value)
1481 ((ConstructorCallMessage)_ccmsg).Uri = (String)value;
1484 ((ConstructorCallMessage)_ccmsg).SetLogicalCallContext(
1485 (LogicalCallContext)value);
1488 // We should not get here!
1489 throw new RemotingException(
1490 Environment.GetResourceString(
1491 "Remoting_Default"));
1497 //+========================================================================
1499 // Synopsis: Specialization of MessageDictionary for ConstructorCallMessage objects
1501 //-========================================================================
1503 internal class CRMDictionary : MessageDictionary
1505 public static String[] CRMkeysFault = {
1508 "__MethodSignature",
1511 public static String[] CRMkeysNoFault = {
1514 "__MethodSignature",
1519 internal IConstructionReturnMessage _crmsg;
1520 internal bool fault;
1522 [System.Security.SecurityCritical] // auto-generated
1523 public CRMDictionary(IConstructionReturnMessage msg, IDictionary idict)
1524 : base( (msg.Exception!=null)? CRMkeysFault : CRMkeysNoFault, idict)
1526 fault = (msg.Exception != null) ;
1530 [System.Security.SecuritySafeCritical] // auto-generated
1531 internal override Object GetMessageValue(int i)
1538 return _crmsg.MethodName;
1540 return _crmsg.MethodSignature;
1542 return _crmsg.TypeName;
1544 return fault ? FetchLogicalCallContext() : _crmsg.ReturnValue;
1548 return FetchLogicalCallContext();
1550 throw new RemotingException(
1551 Environment.GetResourceString(
1552 "Remoting_Default"));
1555 [System.Security.SecurityCritical] // auto-generated
1556 private LogicalCallContext FetchLogicalCallContext()
1558 ReturnMessage retMsg = _crmsg as ReturnMessage;
1561 return retMsg.GetLogicalCallContext();
1565 MethodResponse mr = _crmsg as MethodResponse;
1568 return mr.GetLogicalCallContext();
1572 throw new RemotingException(
1573 Environment.GetResourceString(
1574 "Remoting_Message_BadType"));
1579 [System.Security.SecurityCritical]
1580 internal override void SetSpecialKey(int keyNum, Object value)
1582 // NOTE: we use this for Uri & CallContext only ...
1584 ReturnMessage rm = _crmsg as ReturnMessage;
1585 MethodResponse mr = _crmsg as MethodResponse;
1591 rm.Uri = (String)value;
1598 mr.Uri = (String)value;
1602 throw new RemotingException(
1603 Environment.GetResourceString(
1604 "Remoting_Message_BadType"));
1611 rm.SetLogicalCallContext((LogicalCallContext)value);
1618 mr.SetLogicalCallContext((LogicalCallContext)value);
1622 throw new RemotingException(
1623 Environment.GetResourceString(
1624 "Remoting_Message_BadType"));
1629 throw new RemotingException(
1630 Environment.GetResourceString(
1631 "Remoting_Default"));
1636 //+================================================================================
1638 // Synopsis: Specialization of MessageDictionary for MethodCallMessage
1640 //-========================================================================
1642 internal class MCMDictionary : MessageDictionary
1644 public static String[] MCMkeys = {
1647 "__MethodSignature",
1652 internal IMethodCallMessage _mcmsg; // back pointer to message object
1655 public MCMDictionary(IMethodCallMessage msg, IDictionary idict)
1656 : base(MCMkeys, idict)
1661 [System.Security.SecuritySafeCritical] // auto-generated
1662 internal override Object GetMessageValue(int i)
1669 return _mcmsg.MethodName;
1671 return _mcmsg.MethodSignature;
1673 return _mcmsg.TypeName;
1677 return FetchLogicalCallContext();
1680 // Shouldn't get here.
1681 throw new RemotingException(
1682 Environment.GetResourceString(
1683 "Remoting_Default"));
1686 [System.Security.SecurityCritical] // auto-generated
1687 private LogicalCallContext FetchLogicalCallContext()
1689 Message msg = _mcmsg as Message;
1692 return msg.GetLogicalCallContext();
1696 MethodCall mc = _mcmsg as MethodCall;
1699 return mc.GetLogicalCallContext();
1703 throw new RemotingException(
1704 Environment.GetResourceString(
1705 "Remoting_Message_BadType"));
1710 [System.Security.SecurityCritical]
1711 internal override void SetSpecialKey(int keyNum, Object value)
1713 Message msg = _mcmsg as Message;
1714 MethodCall mc = _mcmsg as MethodCall;
1720 msg.Uri = (String)value;
1722 else if (null != mc)
1724 mc.Uri = (String)value;
1728 throw new RemotingException(
1729 Environment.GetResourceString(
1730 "Remoting_Message_BadType"));
1737 msg.SetLogicalCallContext((LogicalCallContext)value);
1741 throw new RemotingException(
1742 Environment.GetResourceString(
1743 "Remoting_Message_BadType"));
1747 // Shouldn't get here.
1748 throw new RemotingException(
1749 Environment.GetResourceString(
1750 "Remoting_Default"));
1755 //+================================================================================
1757 // Synopsis: Specialization of MessageDictionary for MethodReturnMessage objects
1759 //-================================================================================
1760 internal class MRMDictionary : MessageDictionary
1762 public static String[] MCMkeysFault = {"__CallContext"};
1763 public static String[] MCMkeysNoFault = {
1766 "__MethodSignature",
1772 internal IMethodReturnMessage _mrmsg;
1773 internal bool fault;
1775 [System.Security.SecurityCritical] // auto-generated
1776 public MRMDictionary(IMethodReturnMessage msg, IDictionary idict)
1777 : base((msg.Exception != null) ? MCMkeysFault : MCMkeysNoFault, idict)
1779 fault = (msg.Exception != null) ;
1783 [System.Security.SecuritySafeCritical]
1784 internal override Object GetMessageValue(int i)
1790 return FetchLogicalCallContext();
1794 return _mrmsg.MethodName;
1796 return _mrmsg.MethodSignature;
1798 return _mrmsg.TypeName;
1802 return _mrmsg.Exception;
1806 return _mrmsg.ReturnValue;
1811 return FetchLogicalCallContext();
1813 // Shouldn't get here.
1814 throw new RemotingException(
1815 Environment.GetResourceString(
1816 "Remoting_Default"));
1819 [System.Security.SecurityCritical] // auto-generated
1820 private LogicalCallContext FetchLogicalCallContext()
1822 ReturnMessage rm = _mrmsg as ReturnMessage;
1825 return rm.GetLogicalCallContext();
1829 MethodResponse mr = _mrmsg as MethodResponse;
1832 return mr.GetLogicalCallContext();
1836 StackBasedReturnMessage srm = _mrmsg as StackBasedReturnMessage;
1839 return srm.GetLogicalCallContext();
1843 throw new RemotingException(
1844 Environment.GetResourceString(
1845 "Remoting_Message_BadType"));
1851 [System.Security.SecurityCritical]
1852 internal override void SetSpecialKey(int keyNum, Object value)
1856 // NOTE : we use this for Uri & CallContext only ...
1857 ReturnMessage rm = _mrmsg as ReturnMessage;
1858 MethodResponse mr = _mrmsg as MethodResponse;
1865 rm.Uri = (String)value;
1871 mr.Uri = (String)value;
1875 throw new RemotingException(
1876 Environment.GetResourceString(
1877 "Remoting_Message_BadType"));
1884 rm.SetLogicalCallContext((LogicalCallContext)value);
1891 mr.SetLogicalCallContext((LogicalCallContext)value);
1895 throw new RemotingException(
1896 Environment.GetResourceString(
1897 "Remoting_Message_BadType"));
1902 // Shouldn't get here.
1903 throw new RemotingException(
1904 Environment.GetResourceString(
1905 "Remoting_Default"));
1911 //+================================================================================
1913 // Synopsis: Abstract class to help present a dictionary view of an object
1915 //-================================================================================
1916 internal abstract class MessageDictionary : IDictionary
1918 internal String[] _keys;
1919 internal IDictionary _dict;
1921 internal MessageDictionary(String[] keys, IDictionary idict)
1927 internal bool HasUserData()
1929 // used by message smuggler to determine if there is any custom user
1930 // data in the dictionary
1931 if ((_dict != null) && (_dict.Count > 0))
1937 // used by message smuggler, so that it doesn't have to iterate
1938 // through special keys
1939 internal IDictionary InternalDictionary
1941 get { return _dict; }
1945 internal abstract Object GetMessageValue(int i);
1947 [System.Security.SecurityCritical]
1948 internal abstract void SetSpecialKey(int keyNum, Object value);
1950 public virtual bool IsReadOnly { get { return false; } }
1951 public virtual bool IsSynchronized { get { return false; } }
1952 public virtual bool IsFixedSize { get { return false; } }
1954 public virtual Object SyncRoot { get { return this; } }
1957 public virtual bool Contains(Object key)
1959 if (ContainsSpecialKey(key))
1963 else if (_dict != null)
1965 return _dict.Contains(key);
1970 protected virtual bool ContainsSpecialKey(Object key)
1972 if (!(key is System.String))
1976 String skey = (String) key;
1977 for (int i = 0 ; i < _keys.Length; i++)
1979 if (skey.Equals(_keys[i]))
1987 public virtual void CopyTo(Array array, int index)
1989 for (int i=0; i<_keys.Length; i++)
1991 array.SetValue(GetMessageValue(i), index+i);
1996 _dict.CopyTo(array, index+_keys.Length);
2000 public virtual Object this[Object key]
2004 System.String skey = key as System.String;
2007 for (int i=0; i<_keys.Length; i++)
2009 if (skey.Equals(_keys[i]))
2011 return GetMessageValue(i);
2021 [System.Security.SecuritySafeCritical] //
2024 if (ContainsSpecialKey(key))
2026 if (key.Equals(Message.UriKey))
2028 SetSpecialKey(0,value);
2030 else if (key.Equals(Message.CallContextKey))
2032 SetSpecialKey(1,value);
2036 throw new ArgumentException(
2037 Environment.GetResourceString(
2038 "Argument_InvalidKey"));
2045 _dict = new Hashtable();
2053 IDictionaryEnumerator IDictionary.GetEnumerator()
2055 return new MessageDictionaryEnumerator(this, _dict);
2058 IEnumerator IEnumerable.GetEnumerator()
2060 throw new NotSupportedException();
2064 public virtual void Add(Object key, Object value)
2066 if (ContainsSpecialKey(key))
2068 throw new ArgumentException(
2069 Environment.GetResourceString(
2070 "Argument_InvalidKey"));
2076 // no need to interlock, message object not guaranteed to
2078 _dict = new Hashtable();
2080 _dict.Add(key, value);
2084 public virtual void Clear()
2086 // Remove all the entries from the hash table
2093 public virtual void Remove(Object key)
2095 if (ContainsSpecialKey(key) || (_dict == null))
2097 throw new ArgumentException(
2098 Environment.GetResourceString(
2099 "Argument_InvalidKey"));
2107 public virtual ICollection Keys
2112 int len = _keys.Length;
2113 ICollection c = (_dict != null) ? _dict.Keys : null;
2119 ArrayList l = new ArrayList(len);
2120 for (int i = 0; i<_keys.Length; i++)
2134 public virtual ICollection Values
2138 int len = _keys.Length;
2139 ICollection c = (_dict != null) ? _dict.Keys : null;
2145 ArrayList l = new ArrayList(len);
2147 for (int i = 0; i<_keys.Length; i++)
2149 l.Add(GetMessageValue(i));
2160 public virtual int Count
2166 return _dict.Count+_keys.Length;
2170 return _keys.Length;
2177 //+================================================================================
2179 // Synopsis: Dictionary enumerator for helper class
2181 //-================================================================================
2182 internal class MessageDictionaryEnumerator : IDictionaryEnumerator
2185 private IDictionaryEnumerator _enumHash;
2186 private MessageDictionary _md;
2189 public MessageDictionaryEnumerator(MessageDictionary md, IDictionary hashtable)
2192 if (hashtable != null)
2194 _enumHash = hashtable.GetEnumerator();
2201 // Returns the key of the current element of the enumeration. The returned
2202 // value is undefined before the first call to GetNext and following
2203 // a call to GetNext that returned false. Multiple calls to
2204 // GetKey with no intervening calls to GetNext will return
2209 Message.DebugOut("MessageDE::GetKey i = " + i + "\n");
2212 throw new InvalidOperationException(
2213 Environment.GetResourceString(
2214 "InvalidOperation_InternalState"));
2216 if (i < _md._keys.Length)
2218 return _md._keys[i];
2222 Contract.Assert(_enumHash != null,"_enumHash != null");
2223 return _enumHash.Key;
2228 // Returns the value of the current element of the enumeration. The
2229 // returned value is undefined before the first call to GetNext and
2230 // following a call to GetNext that returned false. Multiple calls
2231 // to GetValue with no intervening calls to GetNext will
2232 // return the same object.
2234 public Object Value {
2238 throw new InvalidOperationException(
2239 Environment.GetResourceString(
2240 "InvalidOperation_InternalState"));
2243 if (i < _md._keys.Length)
2245 return _md.GetMessageValue(i);
2249 Contract.Assert(_enumHash != null,"_enumHash != null");
2250 return _enumHash.Value;
2255 // Advances the enumerator to the next element of the enumeration and
2256 // returns a boolean indicating whether an element is available. Upon
2257 // creation, an enumerator is conceptually positioned before the first
2258 // element of the enumeration, and the first call to GetNext brings
2259 // the first element of the enumeration into view.
2261 public bool MoveNext()
2265 throw new InvalidOperationException(
2266 Environment.GetResourceString(
2267 "InvalidOperation_InternalState"));
2270 if (i < _md._keys.Length)
2276 if (_enumHash != null && _enumHash.MoveNext())
2288 // Returns the current element of the enumeration. The returned value is
2289 // undefined before the first call to MoveNext and following a call
2290 // to MoveNext that returned false. Multiple calls to
2291 // Current with no intervening calls to MoveNext will return
2294 public Object Current {
2300 public DictionaryEntry Entry {
2302 return new DictionaryEntry(Key, Value);
2306 // Resets the enumerator, positioning it before the first element. If an
2307 // Enumerator doesn't support Reset, a NotSupportedException is
2312 if (_enumHash != null)
2319 //+================================================================================
2321 // Synopsis: Message for return from a stack blit call
2323 //-================================================================================
2324 internal class StackBasedReturnMessage : IMethodReturnMessage, IInternalMessage
2329 ArgMapper _argMapper;
2331 internal StackBasedReturnMessage() {}
2333 // NOTE: This method is called multiple times as we reuse the
2334 // message object. Make sure that you reset any fields that you
2335 // add to the message object to the default values. This will
2336 // ensure that the reused message object starts with the correct
2338 internal void InitFields(Message m)
2343 // Remove all the hashtable entries
2348 // Remove all the dictionary entries
2355 [System.Security.SecurityCritical] // auto-generated
2356 get {return _m.Uri;}
2359 public String MethodName
2361 [System.Security.SecurityCritical] // auto-generated
2362 get {return _m.MethodName;}
2365 public String TypeName
2367 [System.Security.SecurityCritical] // auto-generated
2368 get {return _m.TypeName;}
2371 public Object MethodSignature
2373 [System.Security.SecurityCritical] // auto-generated
2374 get {return _m.MethodSignature;}
2377 public MethodBase MethodBase
2379 [System.Security.SecurityCritical] // auto-generated
2380 get {return _m.MethodBase;}
2383 public bool HasVarArgs
2385 [System.Security.SecurityCritical] // auto-generated
2386 get {return _m.HasVarArgs;}
2391 [System.Security.SecurityCritical] // auto-generated
2392 get {return _m.ArgCount;}
2395 [System.Security.SecurityCritical] // auto-generated
2396 public Object GetArg(int argNum) {return _m.GetArg(argNum);}
2397 [System.Security.SecurityCritical] // auto-generated
2398 public String GetArgName(int index) {return _m.GetArgName(index);}
2399 public Object[] Args
2401 [System.Security.SecurityCritical] // auto-generated
2402 get {return _m.Args;}
2404 public LogicalCallContext LogicalCallContext
2406 [System.Security.SecurityCritical] // auto-generated
2407 get { return _m.GetLogicalCallContext(); }
2410 [System.Security.SecurityCritical] // auto-generated
2411 internal LogicalCallContext GetLogicalCallContext() {return _m.GetLogicalCallContext();}
2412 [System.Security.SecurityCritical] // auto-generated
2413 internal LogicalCallContext SetLogicalCallContext(LogicalCallContext callCtx)
2415 return _m.SetLogicalCallContext(callCtx);
2418 public int OutArgCount
2420 [System.Security.SecurityCritical] // auto-generated
2423 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
2424 return _argMapper.ArgCount;
2428 [System.Security.SecurityCritical] // auto-generated
2429 public Object GetOutArg(int argNum)
2431 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
2432 return _argMapper.GetArg(argNum);
2435 [System.Security.SecurityCritical] // auto-generated
2436 public String GetOutArgName(int index)
2438 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
2439 return _argMapper.GetArgName(index);
2441 public Object[] OutArgs
2443 [System.Security.SecurityCritical] // auto-generated
2446 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
2447 return _argMapper.Args;
2451 public Exception Exception
2453 [System.Security.SecurityCritical] // auto-generated
2457 public Object ReturnValue
2459 [System.Security.SecurityCritical] // auto-generated
2460 get {return _m.GetReturnValue();}
2463 public IDictionary Properties
2465 [System.Security.SecurityCritical] // auto-generated
2472 _h = new Hashtable();
2476 _d = new MRMDictionary(this, _h);
2487 ServerIdentity IInternalMessage.ServerIdentityObject
2489 [System.Security.SecurityCritical]
2490 get { return null; }
2491 [System.Security.SecurityCritical]
2495 Identity IInternalMessage.IdentityObject
2497 [System.Security.SecurityCritical]
2498 get { return null; }
2499 [System.Security.SecurityCritical]
2503 [System.Security.SecurityCritical]
2504 void IInternalMessage.SetURI(String val)
2509 [System.Security.SecurityCritical]
2510 void IInternalMessage.SetCallContext(LogicalCallContext newCallContext)
2512 _m.SetLogicalCallContext(newCallContext);
2515 [System.Security.SecurityCritical]
2516 bool IInternalMessage.HasProperties()
2520 } // class StackBasedReturnMessage
2523 //+================================================================================
2525 // Synopsis: Message for return from a stack builder sink call
2527 //-================================================================================
2528 [System.Security.SecurityCritical] // auto-generated_required
2529 [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.Infrastructure)]
2530 [System.Runtime.InteropServices.ComVisible(true)]
2531 public class ReturnMessage : IMethodReturnMessage
2533 internal Object _ret;
2534 internal Object _properties;
2535 internal String _URI;
2536 internal Exception _e;
2537 internal Object[] _outArgs;
2538 internal int _outArgsCount;
2539 internal String _methodName;
2540 internal String _typeName;
2541 internal Type[] _methodSignature;
2542 internal bool _hasVarArgs;
2543 internal LogicalCallContext _callContext;
2544 internal ArgMapper _argMapper;
2545 internal MethodBase _methodBase;
2547 [System.Security.SecurityCritical] // auto-generated
2548 public ReturnMessage(Object ret, Object[] outArgs, int outArgsCount, LogicalCallContext callCtx,
2549 IMethodCallMessage mcm)
2553 _outArgsCount = outArgsCount;
2555 if (callCtx != null)
2556 _callContext = callCtx;
2558 _callContext = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
2563 _methodName = mcm.MethodName;
2564 _methodSignature = null;
2565 _typeName = mcm.TypeName;
2566 _hasVarArgs = mcm.HasVarArgs;
2567 _methodBase = mcm.MethodBase;
2571 [System.Security.SecurityCritical] // auto-generated
2572 public ReturnMessage(Exception e, IMethodCallMessage mcm)
2574 _e = IsCustomErrorEnabled()? new RemotingException(Environment.GetResourceString("Remoting_InternalError")):e;
2575 _callContext = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
2579 _methodName = mcm.MethodName;
2580 _methodSignature = null;
2581 _typeName = mcm.TypeName;
2582 _hasVarArgs = mcm.HasVarArgs;
2583 _methodBase = mcm.MethodBase;
2589 [System.Security.SecurityCritical]
2590 get { return _URI; }
2591 set { _URI = value; }
2593 public String MethodName
2595 [System.Security.SecurityCritical]
2596 get { return _methodName; }
2598 public String TypeName
2600 [System.Security.SecurityCritical]
2601 get { return _typeName; }
2603 public Object MethodSignature
2605 [System.Security.SecurityCritical]
2608 if ((_methodSignature == null) && (_methodBase != null))
2609 _methodSignature = Message.GenerateMethodSignature(_methodBase);
2611 return _methodSignature;
2615 public MethodBase MethodBase
2617 [System.Security.SecurityCritical]
2618 get { return _methodBase; }
2621 public bool HasVarArgs
2623 [System.Security.SecurityCritical]
2633 [System.Security.SecurityCritical]
2636 if (_outArgs == null)
2638 return _outArgsCount;
2642 return _outArgs.Length;
2647 [System.Security.SecurityCritical]
2648 public Object GetArg(int argNum)
2650 if (_outArgs == null)
2652 if ((argNum<0) || (argNum>=_outArgsCount))
2654 throw new ArgumentOutOfRangeException("argNum");
2660 if ((argNum<0) || (argNum>=_outArgs.Length))
2662 throw new ArgumentOutOfRangeException("argNum");
2664 return _outArgs[argNum];
2669 [System.Security.SecurityCritical] // auto-generated
2670 public String GetArgName(int index)
2673 if (_outArgs == null)
2675 if ((index < 0) || (index>=_outArgsCount))
2677 throw new ArgumentOutOfRangeException("index");
2682 if ((index < 0) || (index>=_outArgs.Length))
2684 throw new ArgumentOutOfRangeException("index");
2688 if (_methodBase != null)
2690 RemotingMethodCachedData methodCache = InternalRemotingServices.GetReflectionCachedData(_methodBase);
2691 return methodCache.Parameters[index].Name;
2694 return "__param" + index;
2697 public Object[] Args
2699 [System.Security.SecurityCritical]
2702 if (_outArgs == null)
2704 return new Object[_outArgsCount];
2710 public int OutArgCount
2712 [System.Security.SecurityCritical]
2715 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
2716 return _argMapper.ArgCount;
2720 [System.Security.SecurityCritical]
2721 public Object GetOutArg(int argNum)
2723 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
2724 return _argMapper.GetArg(argNum);
2727 [System.Security.SecurityCritical]
2728 public String GetOutArgName(int index)
2730 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
2731 return _argMapper.GetArgName(index);
2733 public Object[] OutArgs
2735 [System.Security.SecurityCritical]
2738 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
2739 return _argMapper.Args;
2743 public Exception Exception
2745 [System.Security.SecurityCritical]
2748 public virtual Object ReturnValue
2750 [System.Security.SecurityCritical]
2751 get { return _ret; }
2754 public virtual IDictionary Properties
2756 [System.Security.SecurityCritical]
2759 if (_properties == null)
2761 _properties = new MRMDictionary(this, null);
2763 return(MRMDictionary) _properties;
2767 public LogicalCallContext LogicalCallContext
2769 [System.Security.SecurityCritical] // auto-generated
2770 get { return GetLogicalCallContext();}
2774 [System.Security.SecurityCritical] // auto-generated
2775 internal LogicalCallContext GetLogicalCallContext()
2777 if (_callContext == null)
2778 _callContext = new LogicalCallContext();
2779 return _callContext;
2782 internal LogicalCallContext SetLogicalCallContext(LogicalCallContext ctx)
2784 LogicalCallContext old = _callContext;
2789 // used to determine if the properties dictionary has already been created
2790 internal bool HasProperties()
2792 return _properties != null;
2794 [System.Security.SecurityCritical] // auto-generated
2795 static internal bool IsCustomErrorEnabled(){
2796 Object oIsCustomErrorEnabled = CallContext.GetData("__CustomErrorsEnabled");
2797 // The server side will always have this CallContext item set. If it is not set then
2798 // it means this is the client side. In that case customError is false.
2799 return (oIsCustomErrorEnabled == null) ? false:(bool)oIsCustomErrorEnabled;
2802 } // class ReturnMessage
2804 //+================================================================================
2806 // Synopsis: Message used for deserialization of a method call
2808 //-================================================================================
2810 [System.Security.SecurityCritical] // auto-generated_required
2812 [CLSCompliant(false)]
2813 [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.Infrastructure)]
2814 [System.Runtime.InteropServices.ComVisible(true)]
2815 public class MethodCall : IMethodCallMessage, ISerializable, IInternalMessage, ISerializationRootObject
2818 private const BindingFlags LookupAll = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
2819 private const BindingFlags LookupPublic = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
2823 private String methodName;
2824 private MethodBase MI;
2825 private String typeName;
2826 private Object[] args;
2827 private Type[] instArgs;
2828 private LogicalCallContext callContext;
2829 private Type[] methodSignature;
2831 protected IDictionary ExternalProperties = null;
2833 protected IDictionary InternalProperties = null;
2835 private ServerIdentity srvID;
2836 private Identity identity;
2838 private bool fVarArgs = false;
2839 private ArgMapper argMapper;
2842 // MethodCall -- SOAP uses this constructor
2846 [System.Security.SecurityCritical] // auto-generated
2847 public MethodCall(Header[] h1)
2849 Message.DebugOut("MethodCall ctor IN headers: " + (h1 == null ? "<null>" : h1.ToString()) + "\n");
2858 Message.DebugOut("MethodCall ctor OUT\n");
2862 // MethodCall -- this constructor is used for copying an existing message
2865 [System.Security.SecurityCritical] // auto-generated
2866 public MethodCall(IMessage msg)
2869 throw new ArgumentNullException("msg");
2870 Contract.EndContractBlock();
2874 IDictionaryEnumerator de = msg.Properties.GetEnumerator();
2875 while (de.MoveNext())
2877 FillHeader(de.Key.ToString(), de.Value);
2880 IMethodCallMessage mcm = msg as IMethodCallMessage;
2883 MI = mcm.MethodBase;
2888 [System.Security.SecurityCritical] // auto-generated
2889 internal MethodCall(SerializationInfo info, StreamingContext context)
2892 throw new ArgumentNullException("info");
2893 Contract.EndContractBlock();
2896 SetObjectData(info, context);
2900 [System.Security.SecurityCritical] // auto-generated
2901 internal MethodCall(SmuggledMethodCallMessage smuggledMsg, ArrayList deserializedArgs)
2903 uri = smuggledMsg.Uri;
2904 typeName = smuggledMsg.TypeName;
2905 methodName = smuggledMsg.MethodName;
2906 methodSignature = (Type[])smuggledMsg.GetMethodSignature(deserializedArgs);
2907 args = smuggledMsg.GetArgs(deserializedArgs);
2908 instArgs = smuggledMsg.GetInstantiation(deserializedArgs);
2909 callContext = smuggledMsg.GetCallContext(deserializedArgs);
2913 if (smuggledMsg.MessagePropertyCount > 0)
2914 smuggledMsg.PopulateMessageProperties(Properties, deserializedArgs);
2917 [System.Security.SecurityCritical] // auto-generated
2918 internal MethodCall(Object handlerObject, BinaryMethodCallMessage smuggledMsg)
2920 if (handlerObject != null)
2922 uri = handlerObject as String;
2925 // This must be the tranparent proxy
2926 MarshalByRefObject mbr = handlerObject as MarshalByRefObject;
2930 srvID = MarshalByRefObject.GetIdentity(mbr, out fServer) as ServerIdentity;
2936 typeName = smuggledMsg.TypeName;
2937 methodName = smuggledMsg.MethodName;
2938 methodSignature = (Type[])smuggledMsg.MethodSignature;
2939 args = smuggledMsg.Args;
2940 instArgs = smuggledMsg.InstantiationArgs;
2941 callContext = smuggledMsg.LogicalCallContext;
2945 if (smuggledMsg.HasProperties)
2946 smuggledMsg.PopulateMessageProperties(Properties);
2952 // ISerializationRootObject
2955 [System.Security.SecurityCritical] // auto-generated
2956 public void RootSetObjectData(SerializationInfo info, StreamingContext ctx)
2958 SetObjectData(info, ctx);
2962 // SetObjectData -- the class can also be initialized in part or in whole by serialization
2963 // in the SOAP case, both the constructor and SetObjectData init the object, in the non-SOAP
2964 // case, just SetObjectData is called
2967 [System.Security.SecurityCritical] // auto-generated
2968 internal void SetObjectData(SerializationInfo info, StreamingContext context)
2971 throw new ArgumentNullException("info");
2972 Contract.EndContractBlock();
2976 SetObjectFromSoapData(info);
2980 SerializationInfoEnumerator siEnum = info.GetEnumerator();
2981 while (siEnum.MoveNext())
2983 FillHeader(siEnum.Name, siEnum.Value);
2985 if ((context.State == StreamingContextStates.Remoting) &&
2986 (context.Context != null))
2988 Header[] h = context.Context as Header[];
2991 for (int i=0; i<h.Length; i++)
2992 FillHeader(h[i].Name, h[i].Value);
3002 #if FEATURE_REMOTING
3003 // This is used by Remoting
3004 private static Type ResolveTypeRelativeTo(String typeName, int offset, int count, Type serverType)
3006 Type type = ResolveTypeRelativeToBaseTypes(typeName, offset, count, serverType);
3009 // compare against the interface list
3010 // GetInterfaces() returns a complete list of interfaces this type supports
3011 Type[] interfaces = serverType.GetInterfaces();
3012 foreach (Type iface in interfaces)
3014 String ifaceTypeName = iface.FullName;
3015 if (ifaceTypeName.Length == count)
3017 if (String.CompareOrdinal(typeName, offset, ifaceTypeName, 0, count) == 0)
3026 } // ResolveTypeRelativeTo
3028 // This is used by Remoting
3029 private static Type ResolveTypeRelativeToBaseTypes(String typeName, int offset, int count, Type serverType)
3031 // typeName is excepted to contain the full type name
3032 // offset is the start of the full type name within typeName
3033 // count us the number of characters in the full type name
3034 // serverType is the type of the server object
3036 if ((typeName == null) || (serverType == null))
3039 String serverTypeName = serverType.FullName;
3040 if (serverTypeName.Length == count)
3042 if (String.CompareOrdinal(typeName, offset, serverTypeName, 0, count) == 0)
3048 return ResolveTypeRelativeToBaseTypes(typeName, offset, count, serverType.BaseType);
3049 } // ResolveTypeRelativeTo
3050 #endif // FEATURE_REMOTING
3052 internal Type ResolveType()
3058 srvID = IdentityHolder.CasualResolveIdentity(uri) as ServerIdentity;
3062 Type serverType = srvID.GetLastCalledType(typeName);
3063 if (serverType != null)
3065 int startIndex = 0; // start of type name
3067 // check to see if type name starts with "clr:"
3068 if (String.CompareOrdinal(typeName, 0, "clr:", 0, 4) == 0)
3070 // type starts just past "clr:"
3074 // find end of full type name
3075 int index = typeName.IndexOf(',', startIndex);
3077 index = typeName.Length;
3079 serverType = srvID.ServerType;
3080 t = ResolveTypeRelativeTo(typeName, startIndex, index - startIndex, serverType);
3085 // fall back to Type.GetType() in case someone isn't using
3086 // our convention for the TypeName
3087 t = RemotingServices.InternalGetTypeFromQualifiedTypeName(typeName);
3090 srvID.SetLastCalledType(typeName, t);
3096 [System.Security.SecurityCritical] // auto-generated
3097 public void ResolveMethod()
3099 ResolveMethod(true);
3102 [System.Security.SecurityCritical] // auto-generated
3103 internal void ResolveMethod(bool bThrowIfNotResolved)
3105 if ((MI == null) && (methodName != null))
3107 BCLDebug.Trace("REMOTE", "TypeName: " + (typeName == null ? "<null>" : typeName) + "\n");
3110 RuntimeType t = ResolveType() as RuntimeType;
3112 BCLDebug.Trace("REMOTE", "Type: " + (t == null ? "<null>" : t.ToString()) + "\n");
3113 if (methodName.Equals(".ctor"))
3117 throw new RemotingException(
3119 CultureInfo.CurrentCulture, Environment.GetResourceString(
3120 "Remoting_BadType"),
3124 // Note: we reflect on non-public members here .. we do
3125 // block incoming remote calls and allow only specific methods
3126 // that we use for implementation of certain features (eg.
3127 // for remote field access)
3129 // ***********************************************************
3130 // Note: For the common (non-overloaded method, urt-to-urt) case
3131 // methodSignature is null.
3132 // If the call is from a urt client to an overloaded method,
3133 // methodSignature is non-null. We could have a non-null
3134 // methodSignature if the call is from a non-urt client for
3135 // which we have to do special work if the method is overloaded
3136 // (in the try-catch below).
3137 // ***********************************************************
3138 if (null != methodSignature)
3142 int arity = instArgs == null ? 0 : instArgs.Length;
3144 // Handle the common case efficiently, using GetMethod.
3145 // Note that GetMethod doesn't match methods with uninstantiated
3146 // generic arguments, so we can only use the fast case for
3147 // non-generic methods.
3152 MI = t.GetMethod(methodName,
3153 MethodCall.LookupAll,
3155 CallingConventions.Any,
3160 catch (AmbiguousMatchException)
3162 // There is more than one match, so we'll have to do
3167 // Do a more thorough search if the fast case didn't succeed.
3170 // Make a list of all the methods with the right name.
3171 MemberInfo [] methods = t.FindMembers(MemberTypes.Method, MethodCall.LookupAll, Type.FilterName, methodName);
3173 // Filter out all the methods with the wrong arity.
3174 // (Compress them into the start of the array then copy
3175 // them into a new array of exactly the right length).
3177 for (int i = 0; i < methods.Length; i++)
3179 // MakeGenericMethod might throw if the generic arguments
3180 // can't be applied to the method in a type-safe way.
3181 // In that case, continue with the next method.
3184 MethodInfo mi = (MethodInfo)methods[i];
3185 int miArity = mi.IsGenericMethod ? mi.GetGenericArguments().Length : 0;
3186 if (miArity == arity)
3188 // Fill in generic arguments.
3191 mi = mi.MakeGenericMethod(instArgs);
3193 // Got a candidate, compress it back to the
3194 // start of the array.
3195 methods[candidates] = mi;
3199 catch (ArgumentException) { }
3200 catch (VerificationException) { }
3203 MethodInfo[] matches = new MethodInfo[candidates];
3204 for (int i = 0; i < candidates; i++)
3205 matches[i] = (MethodInfo)methods[i];
3207 // Use the default binder to select the right overload
3208 // based on signature.
3209 MI = Type.DefaultBinder.SelectMethod(MethodCall.LookupAll,
3215 BCLDebug.Trace("REMOTE", "Method resolved w/sig ", MI == null ? "<null>" : "<not null>");
3220 // Check the cache to see if you find the methodbase (unless
3221 // the method has an instantiation, in which case the method
3222 // name is not a unique key).
3223 RemotingTypeCachedData typeCache = null;
3224 if (instArgs == null)
3226 typeCache = InternalRemotingServices.GetReflectionCachedData(t);
3227 MI = typeCache.GetLastCalledMethod(methodName);
3232 // This could give us the wrong MethodBase because
3233 // the server and the client types could be of different
3234 // versions. The mismatch is caught either when the server has
3235 // more than one method defined with the same name or when we
3236 // coerce the args and the incoming argument types do not match
3237 // the method signature.
3240 !methodName.Equals(".ctor"),
3241 "unexpected method type");
3243 bool bOverloaded = false;
3247 MI = t.GetMethod(methodName,
3248 MethodCall.LookupAll);
3250 if (instArgs != null && instArgs.Length > 0)
3251 MI = ((MethodInfo)MI).MakeGenericMethod(instArgs);
3253 BCLDebug.Trace("REMOTE", "Method resolved w/name ", MI == null ? "<null>" : methodName);
3254 BCLDebug.Trace("REMOTE", "sig not filled in!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
3256 catch (AmbiguousMatchException)
3258 // This is the case when no methodSignature was found
3259 // but the method is overloaded ..
3260 // (possibly because a non-URT client called us)
3262 ResolveOverloadedMethod(t);
3265 // In the non-URT call, overloaded case, don't cache the MI
3266 // Avoid caching generic methods -- their names aren't a unique key.
3267 if (MI != null && !bOverloaded && typeCache != null)
3268 typeCache.SetLastCalledMethod(methodName, MI);
3271 if (MI == null && bThrowIfNotResolved)
3273 throw new RemotingException(
3275 CultureInfo.CurrentCulture, Environment.GetResourceString(
3276 "Remoting_Message_MethodMissing"),
3283 // Helper that gets called when we attempt to resolve a method
3284 // without an accompanying methodSignature ... current thinking is
3285 // that we should make a good faith attempt by matching argument
3288 void ResolveOverloadedMethod(RuntimeType t)
3290 // args is null the first call from soap because we havem't passed the arguments yet.
3294 MemberInfo[] canidates = t.GetMember(methodName, MemberTypes.Method, MethodCall.LookupPublic);
3296 int canidatesCount = canidates.Length;
3298 if (canidatesCount == 1)
3300 MI = canidates[0] as MethodBase;
3304 if (canidatesCount == 0)
3307 int argCount = args.Length;
3308 MethodBase match = null;
3310 // We will let resolve succeed if exactly one of the overloaded methods matches in terms of argCount
3311 for (int i = 0; i < canidatesCount; i++)
3313 MethodBase canidate = canidates[i] as MethodBase;
3314 if (canidate.GetParameters().Length == argCount)
3317 throw new RemotingException(Environment.GetResourceString("Remoting_AmbiguousMethod"));
3327 // This will find the right overloaded method if the argValues from soap have type information,
3328 // By default parameters will be of type string, this could lead to a wrong choice of methodbase.
3329 void ResolveOverloadedMethod(RuntimeType t, String methodName, ArrayList argNames, ArrayList argValues)
3331 MemberInfo[] canidates = t.GetMember(methodName, MemberTypes.Method, MethodCall.LookupPublic);
3333 int canidatesCount = canidates.Length;
3335 if (canidatesCount == 1)
3337 MI = canidates[0] as MethodBase;
3342 if (canidatesCount == 0)
3345 MethodBase match = null;
3347 for (int i = 0; i < canidatesCount; i++)
3349 MethodBase canidate = canidates[i] as MethodBase;
3351 ParameterInfo[] parameters = canidate.GetParameters();
3353 if (parameters.Length == argValues.Count)
3355 bool isMatch = true;
3356 for (int j = 0; j < parameters.Length; j++)
3358 Type parameterType = parameters[j].ParameterType;
3360 if (parameterType.IsByRef)
3361 parameterType = parameterType.GetElementType();
3363 if (parameterType != argValues[j].GetType())
3378 throw new RemotingException(Environment.GetResourceString("Remoting_AmbiguousMethod"));
3383 // GetObjectData -- not implemented
3387 [System.Security.SecurityCritical] // auto-generated_required
3388 public void GetObjectData(SerializationInfo info, StreamingContext context)
3390 throw new NotSupportedException(
3391 Environment.GetResourceString("NotSupported_Method"));
3395 // SetObjectFromSoapData -- parses soap format for serialization data
3398 [System.Security.SecurityCritical] // auto-generated
3399 internal void SetObjectFromSoapData(SerializationInfo info)
3402 methodName = info.GetString("__methodName");
3403 ArrayList paramNames = (ArrayList)info.GetValue("__paramNameList", typeof(ArrayList));
3405 Hashtable keyToNamespaceTable = (Hashtable)info.GetValue("__keyToNamespaceTable", typeof(Hashtable));
3409 // This is the case where
3410 // 1) there is no signature in the header,
3411 // 2) there is an overloaded method which can not be resolved by a difference in the number of parameters.
3413 // The methodbase can be found only if the parameters from soap have type information
3414 ArrayList argValues = new ArrayList();
3415 ArrayList argNames = paramNames;
3416 // SerializationInfoEnumerator siEnum1 = info.GetEnumerator();
3417 for (int i=0; i<argNames.Count; i++)
3419 argValues.Add(info.GetValue((String)argNames[i], typeof(Object)));
3422 //ambiguous member, try to find methodBase using actual argment types (if available)
3423 RuntimeType t = ResolveType() as RuntimeType;
3426 throw new RemotingException(
3428 CultureInfo.CurrentCulture, Environment.GetResourceString(
3429 "Remoting_BadType"),
3433 ResolveOverloadedMethod(t, methodName, argNames, argValues);
3437 throw new RemotingException(
3439 CultureInfo.CurrentCulture, Environment.GetResourceString(
3440 "Remoting_Message_MethodMissing"),
3448 //Contract.Assert(null != MI, "null != MI");
3450 // get method parameters and parameter maps
3451 RemotingMethodCachedData methodCache = InternalRemotingServices.GetReflectionCachedData(MI);
3452 ParameterInfo[] pinfos = methodCache.Parameters;
3453 int[] marshalRequestArgMap = methodCache.MarshalRequestArgMap;
3455 // check to see if parameters are in-order
3456 Object fUnordered = (null == InternalProperties ? null : InternalProperties["__UnorderedParams"]);
3458 // Create an array for arguments
3459 args = new Object[pinfos.Length];
3461 //SerializationInfoEnumerator siEnum = info.GetEnumerator();
3463 // Fill up the argument array
3464 if (fUnordered != null &&
3465 (fUnordered is System.Boolean) &&
3466 (true == (bool)fUnordered))
3470 for (int i=0; i<paramNames.Count; i++)
3472 memberName = (String)paramNames[i];
3474 "MethodCall::PopulateData members[i].Name: "
3475 + memberName + " substring:>>"
3476 + memberName.Substring(7) + "<<\n");
3479 for (int j=0; j<pinfos.Length; j++)
3481 if (memberName.Equals(pinfos[j].Name))
3483 position = pinfos[j].Position;
3490 if (!memberName.StartsWith("__param", StringComparison.Ordinal))
3492 throw new RemotingException(
3493 Environment.GetResourceString(
3494 "Remoting_Message_BadSerialization"));
3496 position = Int32.Parse(memberName.Substring(7), CultureInfo.InvariantCulture);
3498 if (position >= args.Length)
3500 throw new RemotingException(
3501 Environment.GetResourceString(
3502 "Remoting_Message_BadSerialization"));
3504 args[position] = Message.SoapCoerceArg(info.GetValue(memberName, typeof(Object)), pinfos[position].ParameterType, keyToNamespaceTable);
3509 for (int i=0; i<paramNames.Count; i++)
3511 String memberName = (String)paramNames[i];
3512 args[marshalRequestArgMap[i]] =
3513 Message.SoapCoerceArg(info.GetValue(memberName, typeof(Object)), pinfos[marshalRequestArgMap[i]].ParameterType, keyToNamespaceTable);
3516 PopulateOutArguments(methodCache);
3518 } // SetObjectFromSoapData
3521 [PermissionSet(SecurityAction.Assert, Unrestricted = true)]
3522 void PopulateOutArguments(RemotingMethodCachedData methodCache)
3524 ParameterInfo[] parameterInfos = methodCache.Parameters;
3525 // We need to have a dummy object in the array for out parameters
3526 // that have value types.
3527 foreach (int outArg in methodCache.OutOnlyArgMap)
3529 Type type = parameterInfos[outArg].ParameterType.GetElementType();
3530 if (type.IsValueType)
3531 args[outArg] = Activator.CreateInstance(type, true);
3537 // Init -- constructor helper for for default behavior
3541 public virtual void Init()
3546 // IMethodCallMessage
3552 [System.Security.SecurityCritical]
3555 return(args == null) ? 0 : args.Length;
3560 [System.Security.SecurityCritical]
3561 public Object GetArg(int argNum)
3563 return args[argNum];
3567 [System.Security.SecurityCritical] // auto-generated
3568 public String GetArgName(int index)
3572 RemotingMethodCachedData methodCache = InternalRemotingServices.GetReflectionCachedData(MI);
3573 return methodCache.Parameters[index].Name;
3577 public Object[] Args
3579 [System.Security.SecurityCritical]
3588 public int InArgCount
3590 [System.Security.SecurityCritical]
3593 if (argMapper == null) argMapper = new ArgMapper(this, false);
3594 return argMapper.ArgCount;
3599 [System.Security.SecurityCritical]
3600 public Object GetInArg(int argNum)
3602 if (argMapper == null) argMapper = new ArgMapper(this, false);
3603 return argMapper.GetArg(argNum);
3607 [System.Security.SecurityCritical]
3608 public String GetInArgName(int index)
3610 if (argMapper == null) argMapper = new ArgMapper(this, false);
3611 return argMapper.GetArgName(index);
3614 public Object[] InArgs
3616 [System.Security.SecurityCritical]
3619 if (argMapper == null) argMapper = new ArgMapper(this, false);
3620 return argMapper.Args;
3625 public String MethodName
3627 [System.Security.SecurityCritical]
3628 get { return methodName; }
3631 public String TypeName
3633 [System.Security.SecurityCritical]
3634 get { return typeName; }
3637 public Object MethodSignature
3639 [System.Security.SecurityCritical] // auto-generated
3642 if (methodSignature != null)
3643 return methodSignature;
3644 else if (MI != null)
3645 methodSignature = Message.GenerateMethodSignature(this.MethodBase);
3652 public MethodBase MethodBase
3654 [System.Security.SecurityCritical]
3658 MI = RemotingServices.InternalGetMethodBaseFromMethodMessage(this);
3666 [System.Security.SecurityCritical]
3668 set { uri = value; }
3672 public bool HasVarArgs
3674 [System.Security.SecurityCritical]
3675 get { return fVarArgs; }
3679 public virtual IDictionary Properties
3681 [System.Security.SecurityCritical]
3685 if (InternalProperties == null)
3687 InternalProperties = new Hashtable();
3689 if (ExternalProperties == null)
3691 ExternalProperties = new MCMDictionary(this, InternalProperties);
3693 return ExternalProperties;
3699 public LogicalCallContext LogicalCallContext
3701 [System.Security.SecurityCritical] // auto-generated
3702 get { return GetLogicalCallContext(); }
3705 [System.Security.SecurityCritical] // auto-generated
3706 internal LogicalCallContext GetLogicalCallContext()
3708 if (callContext == null)
3709 callContext = new LogicalCallContext();
3713 internal LogicalCallContext SetLogicalCallContext(LogicalCallContext ctx)
3715 LogicalCallContext old=callContext;
3725 ServerIdentity IInternalMessage.ServerIdentityObject
3727 [System.Security.SecurityCritical]
3728 get { return srvID; }
3729 [System.Security.SecurityCritical]
3730 set { srvID = value; }
3734 Identity IInternalMessage.IdentityObject
3736 [System.Security.SecurityCritical]
3737 get { return identity; }
3738 [System.Security.SecurityCritical]
3739 set { identity = value; }
3743 [System.Security.SecurityCritical]
3744 void IInternalMessage.SetURI(String val)
3750 [System.Security.SecurityCritical]
3751 void IInternalMessage.SetCallContext(LogicalCallContext newCallContext)
3753 callContext = newCallContext;
3757 [System.Security.SecurityCritical]
3758 bool IInternalMessage.HasProperties()
3760 return (ExternalProperties != null) || (InternalProperties != null);
3767 [System.Security.SecurityCritical] // auto-generated
3768 internal void FillHeaders(Header[] h)
3770 FillHeaders(h, false);
3773 [System.Security.SecurityCritical] // auto-generated
3774 private void FillHeaders(Header[] h, bool bFromHeaderHandler)
3779 if (bFromHeaderHandler && fSoap)
3781 // Handle the case of headers coming off the wire in SOAP.
3783 // look for message properties
3785 for (co = 0; co < h.Length; co++)
3787 Header header = h[co];
3788 if (header.HeaderNamespace == "http://schemas.microsoft.com/clr/soap/messageProperties")
3790 // add property to the message
3791 FillHeader(header.Name, header.Value);
3795 // add header to the message as a header
3796 String name = LogicalCallContext.GetPropertyKeyForHeader(header);
3797 FillHeader(name, header);
3804 for (i=0; i<h.Length; i++)
3806 FillHeader(h[i].Name, h[i].Value);
3811 [System.Security.SecurityCritical] // auto-generated
3812 internal virtual bool FillSpecialHeader(String key, Object value)
3818 else if (key.Equals("__Uri"))
3820 uri = (String) value;
3822 else if (key.Equals("__MethodName"))
3824 methodName = (String) value;
3826 else if (key.Equals("__MethodSignature"))
3828 methodSignature = (Type[]) value;
3830 else if (key.Equals("__TypeName"))
3832 typeName = (String) value;
3834 else if (key.Equals("__Args"))
3836 args = (Object[]) value;
3838 else if (key.Equals("__CallContext"))
3840 // if the value is a string, then its the LogicalCallId
3841 if (value is String)
3843 callContext = new LogicalCallContext();
3844 callContext.RemotingData.LogicalCallID = (String) value;
3847 callContext = (LogicalCallContext) value;
3855 [System.Security.SecurityCritical] // auto-generated
3856 internal void FillHeader(String key, Object value)
3858 Message.DebugOut("MethodCall::FillHeader: key:" + key + "\n");
3860 if (!FillSpecialHeader(key,value))
3862 if (InternalProperties == null)
3864 InternalProperties = new Hashtable();
3866 InternalProperties[key] = value;
3872 [System.Security.SecurityCritical] // auto-generated
3873 public virtual Object HeaderHandler(Header[] h)
3875 SerializationMonkey m = (SerializationMonkey) FormatterServices.GetUninitializedObject(typeof(SerializationMonkey));
3876 Header[] newHeaders = null;
3877 if (h != null && h.Length > 0 && h[0].Name == "__methodName")
3879 methodName = (String)h[0].Value;
3882 newHeaders = new Header[h.Length -1];
3883 Array.Copy(h, 1, newHeaders, 0, h.Length-1);
3891 FillHeaders(newHeaders, true);
3892 ResolveMethod(false);
3896 ArgMapper argm = new ArgMapper(MI, false);
3897 m.fieldNames = argm.ArgNames;
3898 m.fieldTypes = argm.ArgTypes;
3905 //+================================================================================
3907 // Synopsis: Message used for deserialization of a construction call
3909 //-================================================================================
3911 [System.Security.SecurityCritical] // auto-generated_required
3913 [CLSCompliant(false)]
3914 [System.Runtime.InteropServices.ComVisible(true)]
3915 public class ConstructionCall : MethodCall, IConstructionCallMessage
3922 internal Type _activationType;
3923 internal String _activationTypeName;
3924 internal IList _contextProperties;
3925 internal Object[] _callSiteActivationAttributes;
3926 internal IActivator _activator;
3930 internal Object _fakeThisPtr; // used for proxyattribute::CI
3938 public ConstructionCall(Header[] headers) : base(headers) {}
3941 public ConstructionCall(IMessage m) : base(m) {}
3942 internal ConstructionCall(SerializationInfo info, StreamingContext context) : base(info, context)
3947 internal Object GetThisPtr()
3949 return _fakeThisPtr;
3951 internal void SetThisPtr(Object obj)
3958 // Function: FillSpecialHeader
3960 // Synopsis: this is the only specialization we need to
3961 // make things go in the right place
3964 [System.Security.SecurityCritical]
3965 internal override bool FillSpecialHeader(String key, Object value)
3971 else if (key.Equals("__ActivationType"))
3973 Contract.Assert(value==null, "Phoney type in CCM");
3974 _activationType = null;
3976 else if (key.Equals("__ContextProperties"))
3978 _contextProperties = (IList) value;
3980 else if (key.Equals("__CallSiteActivationAttributes"))
3982 _callSiteActivationAttributes = (Object[]) value;
3984 else if (key.Equals("__Activator"))
3986 _activator = (IActivator) value;
3988 else if (key.Equals("__ActivationTypeName"))
3990 _activationTypeName = (String) value;
3994 return base.FillSpecialHeader(key, value);
4002 // IConstructionCallMessage
4006 public Object[] CallSiteActivationAttributes
4008 [System.Security.SecurityCritical]
4011 return _callSiteActivationAttributes;
4017 public Type ActivationType
4019 [System.Security.SecurityCritical]
4022 if ((_activationType == null) && (_activationTypeName != null))
4023 _activationType = RemotingServices.InternalGetTypeFromQualifiedTypeName(_activationTypeName, false);
4025 return _activationType;
4030 public String ActivationTypeName
4032 [System.Security.SecurityCritical]
4035 return _activationTypeName;
4040 public IList ContextProperties
4042 [System.Security.SecurityCritical]
4045 if (_contextProperties == null)
4047 _contextProperties = new ArrayList();
4049 return _contextProperties;
4054 public override IDictionary Properties
4056 [System.Security.SecurityCritical]
4061 if (InternalProperties == null)
4063 InternalProperties = new Hashtable();
4065 if (ExternalProperties == null)
4067 ExternalProperties = new CCMDictionary(this, InternalProperties);
4069 return ExternalProperties;
4075 // IConstructionCallMessage::Activator
4077 public IActivator Activator
4079 [System.Security.SecurityCritical]
4080 get { return _activator; }
4081 [System.Security.SecurityCritical]
4082 set { _activator = value; }
4086 //+================================================================================
4088 // Synopsis: Message used for deserialization of a method response
4090 //-================================================================================
4092 [System.Security.SecurityCritical] // auto-generated_required
4094 [CLSCompliant(false)]
4095 [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.Infrastructure)]
4096 [System.Runtime.InteropServices.ComVisible(true)]
4097 public class MethodResponse : IMethodReturnMessage, ISerializable, ISerializationRootObject, IInternalMessage
4099 private MethodBase MI;
4100 private String methodName;
4101 private Type[] methodSignature;
4103 private String typeName;
4104 private Object retVal;
4105 private Exception fault;
4106 private Object[] outArgs;
4107 private LogicalCallContext callContext;
4109 protected IDictionary InternalProperties;
4111 protected IDictionary ExternalProperties;
4113 private int argCount;
4115 private ArgMapper argMapper;
4116 private RemotingMethodCachedData _methodCache;
4118 // Constructor -- this constructor is called only in the SOAP Scenario
4122 [System.Security.SecurityCritical] // auto-generated
4123 public MethodResponse(Header[] h1, IMethodCallMessage mcm)
4126 throw new ArgumentNullException("mcm");
4127 Contract.EndContractBlock();
4129 Message msg = mcm as Message;
4132 MI = (MethodBase)msg.GetMethodBase();
4136 MI = (MethodBase)mcm.MethodBase;
4140 throw new RemotingException(
4142 CultureInfo.CurrentCulture, Environment.GetResourceString(
4143 "Remoting_Message_MethodMissing"),
4148 _methodCache = InternalRemotingServices.GetReflectionCachedData(MI);
4150 argCount = _methodCache.Parameters.Length;
4156 [System.Security.SecurityCritical] // auto-generated
4157 internal MethodResponse(IMethodCallMessage msg,
4158 SmuggledMethodReturnMessage smuggledMrm,
4159 ArrayList deserializedArgs)
4161 MI = (MethodBase)msg.MethodBase;
4162 _methodCache = InternalRemotingServices.GetReflectionCachedData(MI);
4164 methodName = msg.MethodName;
4166 typeName = msg.TypeName;
4168 if (_methodCache.IsOverloaded())
4169 methodSignature = (Type[])msg.MethodSignature;
4171 retVal = smuggledMrm.GetReturnValue(deserializedArgs);
4172 outArgs = smuggledMrm.GetArgs(deserializedArgs);
4173 fault = smuggledMrm.GetException(deserializedArgs);
4175 callContext = smuggledMrm.GetCallContext(deserializedArgs);
4177 if (smuggledMrm.MessagePropertyCount > 0)
4178 smuggledMrm.PopulateMessageProperties(Properties, deserializedArgs);
4180 argCount = _methodCache.Parameters.Length;
4184 [System.Security.SecurityCritical] // auto-generated
4185 internal MethodResponse(IMethodCallMessage msg,
4186 Object handlerObject,
4187 BinaryMethodReturnMessage smuggledMrm)
4192 MI = (MethodBase)msg.MethodBase;
4193 _methodCache = InternalRemotingServices.GetReflectionCachedData(MI);
4195 methodName = msg.MethodName;
4197 typeName = msg.TypeName;
4199 if (_methodCache.IsOverloaded())
4200 methodSignature = (Type[])msg.MethodSignature;
4202 argCount = _methodCache.Parameters.Length;
4206 retVal = smuggledMrm.ReturnValue;
4207 outArgs = smuggledMrm.Args;
4208 fault = smuggledMrm.Exception;
4210 callContext = smuggledMrm.LogicalCallContext;
4212 if (smuggledMrm.HasProperties)
4213 smuggledMrm.PopulateMessageProperties(Properties);
4221 // SetObjectData -- this can be called with the object in two possible states. 1. the object
4222 // is servicing a SOAP response in which it will have been half initialized by the constructor,
4223 // or 2. the object is uninitailized and serialization is passing in the contents.
4225 [System.Security.SecurityCritical] // auto-generated
4226 internal MethodResponse(SerializationInfo info, StreamingContext context)
4229 throw new ArgumentNullException("info");
4230 Contract.EndContractBlock();
4231 SetObjectData(info, context);
4236 [System.Security.SecurityCritical] // auto-generated
4237 public virtual Object HeaderHandler(Header[] h)
4239 SerializationMonkey m = (SerializationMonkey) FormatterServices.GetUninitializedObject(typeof(SerializationMonkey));
4241 Header[] newHeaders = null;
4242 if (h != null && h.Length > 0 && h[0].Name == "__methodName")
4246 newHeaders = new Header[h.Length -1];
4247 Array.Copy(h, 1, newHeaders, 0, h.Length-1);
4255 Type retType = null;
4256 MethodInfo mi = MI as MethodInfo;
4259 retType = mi.ReturnType;
4262 ParameterInfo[] pinfos = _methodCache.Parameters;
4265 int outParamsCount = _methodCache.MarshalResponseArgMap.Length;
4266 if (!((retType == null) || (retType == typeof(void))))
4269 Type[] paramTypes = new Type[outParamsCount];
4270 String[] paramNames = new String[outParamsCount];
4271 int paramTypesIndex = 0;
4272 if (!((retType == null) || (retType == typeof(void))))
4274 paramTypes[paramTypesIndex++] = retType;
4277 foreach (int i in _methodCache.MarshalResponseArgMap)
4279 paramNames[paramTypesIndex] = pinfos[i].Name;
4280 if (pinfos[i].ParameterType.IsByRef)
4281 paramTypes[paramTypesIndex++] = pinfos[i].ParameterType.GetElementType();
4283 paramTypes[paramTypesIndex++] = pinfos[i].ParameterType;
4286 ((IFieldInfo)m).FieldTypes = paramTypes;
4287 ((IFieldInfo)m).FieldNames = paramNames;
4288 FillHeaders(newHeaders, true);
4294 // ISerializationRootObject
4297 [System.Security.SecurityCritical] // auto-generated
4298 public void RootSetObjectData(SerializationInfo info, StreamingContext ctx)
4300 SetObjectData(info, ctx);
4303 [System.Security.SecurityCritical] // auto-generated
4304 internal void SetObjectData(SerializationInfo info, StreamingContext ctx)
4307 throw new ArgumentNullException("info");
4308 Contract.EndContractBlock();
4312 SetObjectFromSoapData(info);
4316 SerializationInfoEnumerator e = info.GetEnumerator();
4320 while (e.MoveNext())
4322 if (e.Name.Equals("__return"))
4327 if (e.Name.Equals("__fault"))
4330 fault = (Exception)e.Value;
4334 FillHeader(e.Name, e.Value);
4336 if ((excep) && (ret))
4338 throw new RemotingException(
4339 Environment.GetResourceString(
4340 "Remoting_Message_BadSerialization"));
4349 // GetObjectData -- not implemented
4353 [System.Security.SecurityCritical] // auto-generated_required
4354 public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
4356 throw new NotSupportedException(
4357 Environment.GetResourceString("NotSupported_Method"));
4361 // SetObjectFromSoapData -- assumes SOAP format and populates the arguments array
4364 internal void SetObjectFromSoapData(SerializationInfo info)
4366 //SerializationInfoEnumerator e = info.GetEnumerator();
4368 Hashtable keyToNamespaceTable = (Hashtable)info.GetValue("__keyToNamespaceTable", typeof(Hashtable));
4369 ArrayList paramNames = (ArrayList)info.GetValue("__paramNameList", typeof(ArrayList));
4370 SoapFault soapFault = (SoapFault)info.GetValue("__fault", typeof(SoapFault));
4372 if (soapFault != null)
4374 ServerFault serverFault = soapFault.Detail as ServerFault;
4375 if (null != serverFault)
4377 // Server Fault information
4378 if (serverFault.Exception != null)
4379 fault = serverFault.Exception;
4382 Type exceptionType = Type.GetType(serverFault.ExceptionType, false, false);
4383 if (exceptionType == null)
4385 // Exception type cannot be resolved, use a ServerException
4386 StringBuilder sb = new StringBuilder();
4387 sb.Append("\nException Type: ");
4388 sb.Append(serverFault.ExceptionType);
4390 sb.Append("Exception Message: ");
4391 sb.Append(serverFault.ExceptionMessage);
4393 sb.Append(serverFault.StackTrace);
4394 fault = new ServerException(sb.ToString());
4398 // Exception type can be resolved, throw the exception
4399 Object[] args = {serverFault.ExceptionMessage};
4400 fault = (Exception)Activator.CreateInstance(
4402 BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.CreateInstance,
4410 else if ((soapFault.Detail != null) && (soapFault.Detail.GetType() == typeof(String)) && (!(((String)soapFault.Detail).Length == 0)))
4412 fault = new ServerException((String)soapFault.Detail);
4416 fault = new ServerException(soapFault.FaultString);
4422 MethodInfo mi = MI as MethodInfo;
4423 int paramNameIndex = 0;
4426 Type retType = mi.ReturnType;
4427 if (retType != typeof(void))
4430 Object returnValue = info.GetValue((String)paramNames[0], typeof(Object));
4431 if (returnValue is String)
4432 retVal = Message.SoapCoerceArg(returnValue, retType, keyToNamespaceTable);
4434 retVal = returnValue;
4438 // populate the args array
4439 ParameterInfo[] pinfos = _methodCache.Parameters;
4441 Object fUnordered = (InternalProperties == null) ? null : InternalProperties["__UnorderedParams"];
4442 if (fUnordered != null &&
4443 (fUnordered is System.Boolean) &&
4444 (true == (bool)fUnordered))
4447 for (int i=paramNameIndex; i<paramNames.Count; i++)
4449 String memberName = (String)paramNames[i];
4451 // check for the parameter name
4454 for (int j=0; j<pinfos.Length; j++)
4456 if (memberName.Equals(pinfos[j].Name))
4458 position = pinfos[j].Position;
4462 // no name so check for well known name
4466 if (!memberName.StartsWith("__param", StringComparison.Ordinal))
4468 throw new RemotingException(
4469 Environment.GetResourceString(
4470 "Remoting_Message_BadSerialization"));
4472 position = Int32.Parse(memberName.Substring(7), CultureInfo.InvariantCulture);
4475 // if still not resolved then throw
4477 if (position >= argCount)
4479 throw new RemotingException(
4480 Environment.GetResourceString(
4481 "Remoting_Message_BadSerialization"));
4484 // store the arg in the parameter array
4486 if (outArgs == null)
4488 outArgs = new Object[argCount];
4490 outArgs[position]= Message.SoapCoerceArg(info.GetValue(memberName, typeof(Object)), pinfos[position].ParameterType, keyToNamespaceTable);
4496 if (argMapper == null) argMapper = new ArgMapper(this, true);
4497 for (int j=paramNameIndex; j<paramNames.Count; j++)
4499 String memberName = (String)paramNames[j];
4500 if (outArgs == null)
4502 outArgs = new Object[argCount];
4505 int position = argMapper.Map[j-paramNameIndex];
4506 outArgs[position] = Message.SoapCoerceArg(info.GetValue(memberName, typeof(Object)), pinfos[position].ParameterType, keyToNamespaceTable);
4509 } // SetObjectFromSoapData
4513 [System.Security.SecurityCritical] // auto-generated
4514 internal LogicalCallContext GetLogicalCallContext()
4516 if (callContext == null)
4517 callContext = new LogicalCallContext();
4521 internal LogicalCallContext SetLogicalCallContext(LogicalCallContext ctx)
4523 LogicalCallContext old=callContext;
4529 // IMethodReturnMessage
4535 [System.Security.SecurityCritical]
4537 set { uri = value; }
4540 public String MethodName
4542 [System.Security.SecurityCritical]
4543 get { return methodName; }
4546 public String TypeName
4548 [System.Security.SecurityCritical]
4549 get { return typeName; }
4552 public Object MethodSignature
4554 [System.Security.SecurityCritical]
4555 get { return methodSignature; }
4558 public MethodBase MethodBase
4560 [System.Security.SecurityCritical]
4566 public bool HasVarArgs
4568 [System.Security.SecurityCritical]
4579 [System.Security.SecurityCritical]
4582 if (outArgs == null)
4585 return outArgs.Length;
4589 [System.Security.SecurityCritical]
4590 public Object GetArg(int argNum) { return outArgs[argNum]; }
4592 [System.Security.SecurityCritical] // auto-generated
4593 public String GetArgName(int index)
4597 RemotingMethodCachedData methodCache = InternalRemotingServices.GetReflectionCachedData(MI);
4598 ParameterInfo[] paramInfo = methodCache.Parameters;
4599 if (index < 0 || index >= paramInfo.Length)
4600 throw new ArgumentOutOfRangeException("index");
4602 return methodCache.Parameters[index].Name;
4605 return "__param" + index;
4608 public Object[] Args
4610 [System.Security.SecurityCritical]
4611 get { return outArgs; }
4615 public int OutArgCount
4617 [System.Security.SecurityCritical]
4620 if (argMapper == null) argMapper = new ArgMapper(this, true);
4621 return argMapper.ArgCount;
4626 [System.Security.SecurityCritical]
4627 public Object GetOutArg(int argNum)
4629 if (argMapper == null) argMapper = new ArgMapper(this, true);
4630 return argMapper.GetArg(argNum);
4634 [System.Security.SecurityCritical]
4635 public String GetOutArgName(int index)
4637 if (argMapper == null) argMapper = new ArgMapper(this, true);
4638 return argMapper.GetArgName(index);
4641 public Object[] OutArgs
4643 [System.Security.SecurityCritical]
4646 if (argMapper == null) argMapper = new ArgMapper(this, true);
4647 return argMapper.Args;
4652 public Exception Exception
4654 [System.Security.SecurityCritical]
4655 get { return fault; }
4658 public Object ReturnValue
4660 [System.Security.SecurityCritical]
4661 get { return retVal; }
4666 public virtual IDictionary Properties
4668 [System.Security.SecurityCritical]
4673 if (InternalProperties == null)
4675 InternalProperties = new Hashtable();
4677 if (ExternalProperties == null)
4679 ExternalProperties = new MRMDictionary(this, InternalProperties);
4681 return ExternalProperties;
4687 public LogicalCallContext LogicalCallContext
4689 [System.Security.SecurityCritical] // auto-generated
4690 get { return GetLogicalCallContext();}
4696 [System.Security.SecurityCritical] // auto-generated
4697 internal void FillHeaders(Header[] h)
4699 FillHeaders(h, false);
4703 [System.Security.SecurityCritical] // auto-generated
4704 private void FillHeaders(Header[] h, bool bFromHeaderHandler)
4709 if (bFromHeaderHandler && fSoap)
4711 // Handle the case of headers coming off the wire in SOAP.
4713 // look for message properties
4715 for (co = 0; co < h.Length; co++)
4717 Header header = h[co];
4718 if (header.HeaderNamespace == "http://schemas.microsoft.com/clr/soap/messageProperties")
4720 // add property to the message
4721 FillHeader(header.Name, header.Value);
4725 // add header to the message as a header
4726 String name = LogicalCallContext.GetPropertyKeyForHeader(header);
4727 FillHeader(name, header);
4733 for (int i=0; i<h.Length; i++)
4735 FillHeader(h[i].Name, h[i].Value);
4741 [System.Security.SecurityCritical] // auto-generated
4742 internal void FillHeader(String name, Object value)
4744 Message.DebugOut("MethodCall::FillHeaders: name: " + (name == null ? "NULL" : name) + "\n");
4745 Message.DebugOut("MethodCall::FillHeaders: Value.GetClass: " + (value == null ? "NULL" : value.GetType().FullName) + "\n");
4746 Message.DebugOut("MethodCall::FillHeaders: Value.ToString: " + (value == null ? "NULL" : value.ToString()) + "\n");
4748 if (name.Equals("__MethodName"))
4750 methodName = (String) value;
4752 else if (name.Equals("__Uri"))
4754 uri = (String) value;
4756 else if (name.Equals("__MethodSignature"))
4758 methodSignature = (Type[]) value;
4760 else if (name.Equals("__TypeName"))
4762 typeName = (String) value;
4764 else if (name.Equals("__OutArgs"))
4766 outArgs = (Object[]) value;
4768 else if (name.Equals("__CallContext"))
4770 // if the value is a string, then its the LogicalCallId
4771 if (value is String)
4773 callContext = new LogicalCallContext();
4774 callContext.RemotingData.LogicalCallID = (String) value;
4777 callContext = (LogicalCallContext) value;
4779 else if (name.Equals("__Return"))
4785 if (InternalProperties == null)
4787 InternalProperties = new Hashtable();
4789 InternalProperties[name] = value;
4798 ServerIdentity IInternalMessage.ServerIdentityObject
4800 [System.Security.SecurityCritical]
4801 get { return null; }
4802 [System.Security.SecurityCritical]
4807 Identity IInternalMessage.IdentityObject
4809 [System.Security.SecurityCritical]
4810 get { return null; }
4811 [System.Security.SecurityCritical]
4816 [System.Security.SecurityCritical]
4817 void IInternalMessage.SetURI(String val)
4824 [System.Security.SecurityCritical]
4825 void IInternalMessage.SetCallContext(LogicalCallContext newCallContext)
4827 callContext = newCallContext;
4831 [System.Security.SecurityCritical]
4832 bool IInternalMessage.HasProperties()
4834 return (ExternalProperties != null) || (InternalProperties != null);
4837 } // class MethodResponse
4839 internal interface ISerializationRootObject
4841 [System.Security.SecurityCritical] // auto-generated_required
4842 void RootSetObjectData(SerializationInfo info, StreamingContext ctx);
4846 internal class SerializationMonkey : ISerializable, IFieldInfo
4848 internal ISerializationRootObject _obj;
4849 internal String[] fieldNames = null;
4850 internal Type[] fieldTypes = null;
4852 [System.Security.SecurityCritical] // auto-generated
4853 internal SerializationMonkey(SerializationInfo info, StreamingContext ctx)
4855 Contract.Assert(_obj != null, "SerializationMonkey's _obj field should have been initialized elsewhere with a special hack.");
4856 _obj.RootSetObjectData(info, ctx);
4859 [System.Security.SecurityCritical] // auto-generated_required
4860 public void GetObjectData(SerializationInfo info, StreamingContext context)
4862 throw new NotSupportedException(
4863 Environment.GetResourceString(
4864 "NotSupported_Method"));
4867 public String[] FieldNames
4869 [System.Security.SecurityCritical] // auto-generated
4870 get {return fieldNames;}
4871 [System.Security.SecurityCritical] // auto-generated
4872 set {fieldNames = value;}
4875 public Type[] FieldTypes
4877 [System.Security.SecurityCritical] // auto-generated
4878 get {return fieldTypes;}
4879 [System.Security.SecurityCritical] // auto-generated
4880 set {fieldTypes = value;}
4886 //+================================================================================
4888 // Synopsis: Message used for deserialization of a method construction
4890 //-================================================================================
4892 [System.Security.SecurityCritical] // auto-generated_required
4894 [CLSCompliant(false)]
4895 [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.Infrastructure)]
4896 [System.Runtime.InteropServices.ComVisible(true)]
4897 public class ConstructionResponse : MethodResponse, IConstructionReturnMessage
4900 public ConstructionResponse(Header[] h, IMethodCallMessage mcm) : base(h, mcm) {}
4901 internal ConstructionResponse(SerializationInfo info, StreamingContext context) : base (info, context) {}
4904 public override IDictionary Properties
4906 [System.Security.SecurityCritical]
4911 if (InternalProperties == null)
4913 InternalProperties = new Hashtable();
4915 if (ExternalProperties == null)
4917 ExternalProperties = new CRMDictionary(this, InternalProperties);
4919 return ExternalProperties;
4925 // This is a special message used for helping someone make a transition
4926 // into a Context (or AppDomain) and back out. This is intended as a replacement
4927 // of the callBack object mechanism which is expensive since it involves
4928 // 2 round trips (one to get the callback object) and one to make the call
4929 // on it. Furthermore the callBack object scheme in cross domain cases would
4930 // involve unnecessary marshal/unmarshal-s of vari'ous callBack objects.
4932 // We implement IInternalMessage and do our own magic when various
4933 // infrastructure sinks ask for serverID etc. Bottomline intent is to make
4934 // everything look like a complete remote call with all the entailing transitions
4935 // and executing some delegate in another context (or appdomain) without
4936 // actually having a proxy to call "Invoke" on or a server object to "Dispatch"
4939 internal class TransitionCall
4940 :IMessage, IInternalMessage, IMessageSink, ISerializable
4942 IDictionary _props; // For IMessage::GetDictionary
4943 IntPtr _sourceCtxID; // Where the request emerged
4944 IntPtr _targetCtxID; // Where the request should execute
4945 int _targetDomainID; // Non zero if we are going to another domain
4946 ServerIdentity _srvID; // Created serverID
4947 Identity _ID; // Created ID
4949 CrossContextDelegate _delegate; // The delegate to execute for the cross context case
4950 IntPtr _eeData; // Used for DoCallbackInEE
4952 // The _delegate should really be on an agile object otherwise
4953 // the whole point of doing a callBack is moot. However, even if it
4954 // is not, remoting and serialization together will ensure that
4955 // everything happens as expected and there is no smuggling.
4957 [System.Security.SecurityCritical] // auto-generated
4958 internal TransitionCall(
4960 CrossContextDelegate deleg)
4962 Contract.Assert(targetCtxID!=IntPtr.Zero, "bad target ctx for call back");
4963 _sourceCtxID = Thread.CurrentContext.InternalContextID;
4964 _targetCtxID = targetCtxID;
4966 _targetDomainID = 0;
4967 _eeData = IntPtr.Zero;
4969 // We are going to another context in the same app domain
4970 _srvID = new ServerIdentity(
4972 Thread.GetContextInternal(_targetCtxID));
4974 _ID.RaceSetChannelSink(CrossContextChannel.MessageSink);
4975 _srvID.RaceSetServerObjectChain(this);
4977 //DBG Console.WriteLine("### TransitionCall ctor: " + Int32.Format(_sourceCtxID,"x") + ":" + Int32.Format(_targetCtxID,"x"));
4981 // This constructor should be used for cross appdomain case.
4982 [System.Security.SecurityCritical] // auto-generated
4983 internal TransitionCall(IntPtr targetCtxID, IntPtr eeData, int targetDomainID)
4985 Contract.Assert(targetCtxID != IntPtr.Zero, "bad target ctx for call back");
4986 Contract.Assert(targetDomainID !=0, "bad target ctx for call back");
4988 _sourceCtxID = Thread.CurrentContext.InternalContextID;
4989 _targetCtxID = targetCtxID;
4991 _targetDomainID = targetDomainID;
4995 // In the cross domain case, the client side just has a base Identity
4996 // and the server domain has the Server identity. We fault in the latter
4997 // when requested later.
4999 // We are going to a context in another app domain
5001 _ID = new Identity("TransitionCallURI", null);
5003 // Create the data needed for the channel sink creation
5004 CrossAppDomainData data =
5005 new CrossAppDomainData(_targetCtxID,
5007 Identity.ProcessGuid);
5009 IMessageSink channelSink =
5010 CrossAppDomainChannel.AppDomainChannel.CreateMessageSink(
5013 out unUsed);//out objURI
5015 Contract.Assert(channelSink != null, "X-domain transition failure");
5016 _ID.RaceSetChannelSink(channelSink);
5020 internal TransitionCall(SerializationInfo info, StreamingContext context)
5022 if (info == null || (context.State != StreamingContextStates.CrossAppDomain))
5024 throw new ArgumentNullException("info");
5026 Contract.EndContractBlock();
5028 _props = (IDictionary)info.GetValue("props", typeof(IDictionary));
5029 _delegate = (CrossContextDelegate) info.GetValue("delegate", typeof(CrossContextDelegate));
5030 _sourceCtxID = (IntPtr) info.GetValue("sourceCtxID", typeof(IntPtr));
5031 _targetCtxID = (IntPtr) info.GetValue("targetCtxID", typeof(IntPtr));
5032 _eeData = (IntPtr) info.GetValue("eeData", typeof(IntPtr));
5034 _targetDomainID = info.GetInt32("targetDomainID");
5035 Contract.Assert(_targetDomainID != 0, "target domain should be non-zero");
5038 //IMessage::GetProperties
5039 public IDictionary Properties
5041 [System.Security.SecurityCritical] // auto-generated
5050 _props = new Hashtable();
5058 //IInternalMessage::ServerIdentityObject
5059 ServerIdentity IInternalMessage.ServerIdentityObject
5061 [System.Security.SecurityCritical]
5064 if ( (_targetDomainID!=0) && _srvID == null)
5066 // We should now be in the target context! (We should not be
5067 // attempting to get the server identity in the client domain).
5068 Contract.Assert(Thread.CurrentContext.InternalContextID
5070 "ServerID requested in wrong appDomain!");
5073 /*DBG Console.WriteLine("### Get SrvID: thrdCtxID== " + Int32.Format(Thread.CurrentContext.InternalContextID,"x"));
5074 Console.WriteLine("### Get SrvID: _targetCtxID" + Int32.Format(_targetCtxID,"x")); DBG*/
5076 // NOTE: if we don't have a managed context object
5077 // corresponding to the targetCtxID ... we just use
5078 // the default context for the AppDomain. This could
5079 // be a problem if by some means we could have
5080 // a non-default target VM context without a managed
5081 // context object associated with it.
5082 Context ctx = Thread.GetContextInternal(_targetCtxID);
5085 ctx = Context.DefaultContext;
5087 Contract.Assert(ctx != null, "Null target context unexpected!");
5088 _srvID = new ServerIdentity(
5090 Thread.GetContextInternal(_targetCtxID));
5092 _srvID.RaceSetServerObjectChain(this);
5097 [System.Security.SecurityCritical]
5100 throw new RemotingException(
5101 Environment.GetResourceString(
5102 "Remoting_Default"));
5106 //IInternalMessage::IdentityObject
5107 Identity IInternalMessage.IdentityObject
5109 [System.Security.SecurityCritical]
5114 [System.Security.SecurityCritical]
5117 throw new RemotingException(
5118 Environment.GetResourceString(
5119 "Remoting_Default"));
5123 //IInternalMessage::SetURI
5124 [System.Security.SecurityCritical]
5125 void IInternalMessage.SetURI(String uri)
5127 throw new RemotingException(
5128 Environment.GetResourceString(
5129 "Remoting_Default"));
5132 [System.Security.SecurityCritical]
5133 void IInternalMessage.SetCallContext(LogicalCallContext callContext)
5135 throw new RemotingException(
5136 Environment.GetResourceString(
5137 "Remoting_Default"));
5140 [System.Security.SecurityCritical]
5141 bool IInternalMessage.HasProperties()
5143 throw new RemotingException(
5144 Environment.GetResourceString(
5145 "Remoting_Default"));
5149 //IMessage::SyncProcessMessage
5150 [System.Security.SecurityCritical] // auto-generated
5151 public IMessage SyncProcessMessage(IMessage msg)
5154 Thread.CurrentContext.InternalContextID == _targetCtxID,
5155 "Transition message routed to wrong context");
5159 LogicalCallContext oldcctx = Message.PropagateCallContextFromMessageToThread(msg);
5160 if (_delegate != null)
5166 // This is the cross appdomain case, so we need to construct
5167 // the delegate and call on it.
5168 CallBackHelper cb = new CallBackHelper(
5172 CrossContextDelegate ctxDel = new CrossContextDelegate(cb.Func);
5175 Message.PropagateCallContextFromThreadToMessage(msg, oldcctx);
5180 ReturnMessage retMsg = new ReturnMessage(e, new ErrorMessage());
5181 retMsg.SetLogicalCallContext(
5182 (LogicalCallContext) msg.Properties[Message.CallContextKey]);
5189 //IMessage::AsyncProcessMessage
5190 [System.Security.SecurityCritical] // auto-generated
5191 public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
5193 IMessage retMsg = SyncProcessMessage(msg);
5194 replySink.SyncProcessMessage(retMsg);
5198 //IMessage::GetNextSink()
5199 public IMessageSink NextSink
5201 [System.Security.SecurityCritical] // auto-generated
5205 //ISerializable::GetObjectData
5206 [System.Security.SecurityCritical] // auto-generated_required
5207 public void GetObjectData(SerializationInfo info, StreamingContext context)
5209 if (info == null || (context.State != StreamingContextStates.CrossAppDomain))
5211 throw new ArgumentNullException("info");
5213 Contract.EndContractBlock();
5214 info.AddValue("props", _props, typeof(IDictionary));
5215 info.AddValue("delegate", _delegate, typeof(CrossContextDelegate));
5216 info.AddValue("sourceCtxID", _sourceCtxID);
5217 info.AddValue("targetCtxID", _targetCtxID);
5218 info.AddValue("targetDomainID", _targetDomainID);
5219 info.AddValue("eeData", _eeData);
5222 }// class TransitionCall
5224 internal class ArgMapper
5228 RemotingMethodCachedData _methodCachedData;
5230 [System.Security.SecurityCritical] // auto-generated
5231 internal ArgMapper(IMethodMessage mm, bool fOut)
5234 MethodBase mb = (MethodBase)_mm.MethodBase;
5236 InternalRemotingServices.GetReflectionCachedData(mb);
5239 _map = _methodCachedData.MarshalResponseArgMap;
5241 _map = _methodCachedData.MarshalRequestArgMap;
5244 [System.Security.SecurityCritical] // auto-generated
5245 internal ArgMapper(MethodBase mb, bool fOut)
5248 InternalRemotingServices.GetReflectionCachedData(mb);
5251 _map = _methodCachedData.MarshalResponseArgMap;
5253 _map = _methodCachedData.MarshalRequestArgMap;
5259 get { return _map; }
5262 internal int ArgCount
5277 [System.Security.SecurityCritical] // auto-generated
5278 internal Object GetArg(int argNum)
5281 if (_map == null || argNum < 0 || argNum >= _map.Length)
5283 throw new InvalidOperationException(
5284 Environment.GetResourceString(
5285 "InvalidOperation_InternalState"));
5289 return _mm.GetArg(_map[argNum]);
5293 [System.Security.SecurityCritical] // auto-generated
5294 internal String GetArgName(int argNum)
5296 if (_map == null || argNum < 0 || argNum >= _map.Length)
5298 throw new InvalidOperationException(
5299 Environment.GetResourceString(
5300 "InvalidOperation_InternalState"));
5304 return _mm.GetArgName(_map[argNum]);
5308 internal Object[] Args
5310 [System.Security.SecurityCritical] // auto-generated
5319 Object[] ret = new Object[_map.Length];
5320 for(int i=0; i<_map.Length; i++)
5322 ret[i] = _mm.GetArg(_map[i]);
5329 internal Type[] ArgTypes
5336 ParameterInfo[] pi = _methodCachedData.Parameters;
5337 ret = new Type[_map.Length];
5338 for (int i=0; i<_map.Length; i++)
5340 ret[i] = pi[_map[i]].ParameterType;
5347 internal String[] ArgNames
5351 String[] ret = null;
5354 ParameterInfo[] pi = _methodCachedData.Parameters;
5355 ret = new String[_map.Length];
5356 for (int i=0; i<_map.Length; i++)
5358 ret[i] = pi[_map[i]].Name;
5367 // Helper functions for getting argument maps
5370 internal static void GetParameterMaps(ParameterInfo[] parameters,
5371 out int[] inRefArgMap,
5372 out int[] outRefArgMap,
5373 out int[] outOnlyArgMap,
5374 out int[] nonRefOutArgMap,
5375 out int[] marshalRequestMap,
5376 out int[] marshalResponseMap)
5381 int outRefCount = 0;
5382 int outOnlyCount = 0;
5383 int nonRefOutCount = 0;
5385 int marshalRequestCount = 0;
5386 int marshalResponseCount = 0;
5387 int[] tempMarshalRequestMap = new int[parameters.Length];
5388 int[] tempMarshalResponseMap = new int[parameters.Length];
5390 // count instances of each type of parameter
5392 foreach (ParameterInfo param in parameters)
5394 bool bIsIn = param.IsIn; // [In]
5395 bool bIsOut = param.IsOut; // [Out] note: out int a === [Out] ref int b
5397 bool bIsByRef = param.ParameterType.IsByRef; // (ref or normal)
5401 // it's a normal parameter (always passed in)
5419 // create maps for marshaling
5420 bool bMarshalIn = false;
5421 bool bMarshalOut = false;
5424 if (bIsIn == bIsOut)
5426 // "ref int a" or "[In, Out] ref int a"
5432 // "[In] ref int a" or "out int a"
5434 bMarshalOut = bIsOut;
5439 // "int a" or "[In, Out] a"
5441 bMarshalOut = bIsOut;
5446 tempMarshalRequestMap[marshalRequestCount++] = co;
5449 tempMarshalResponseMap[marshalResponseCount++] = co;
5451 co++; // parameter index
5452 } // foreach (ParameterInfo param in parameters)
5454 inRefArgMap = new int[inRefCount];
5455 outRefArgMap = new int[outRefCount];
5456 outOnlyArgMap = new int[outOnlyCount];
5457 nonRefOutArgMap = new int[nonRefOutCount];
5464 // build up parameter maps
5465 for (co = 0; co < parameters.Length; co++)
5467 ParameterInfo param = parameters[co];
5469 bool bIsOut = param.IsOut; // [Out] note: out int a === [Out] ref int b
5471 bool bIsByRef = param.ParameterType.IsByRef; // (ref or normal)
5475 // it's an in parameter
5476 inRefArgMap[inRefCount++] = co;
5478 nonRefOutArgMap[nonRefOutCount++] = co;
5483 outRefArgMap[outRefCount++] = co;
5484 outOnlyArgMap[outOnlyCount++] = co;
5488 inRefArgMap[inRefCount++] = co;
5490 outRefArgMap[outRefCount++] = co;
5494 // copy over marshal maps
5495 marshalRequestMap = new int[marshalRequestCount];
5496 Array.Copy(tempMarshalRequestMap, marshalRequestMap, marshalRequestCount);
5498 marshalResponseMap = new int[marshalResponseCount];
5499 Array.Copy(tempMarshalResponseMap, marshalResponseMap, marshalResponseCount);
5501 } // GetParameterMaps
5504 // Helper methods for expanding and contracting argument lists
5505 // when translating from async methods to sync methods and back.
5508 internal static Object[] ExpandAsyncEndArgsToSyncArgs(RemotingMethodCachedData syncMethod,
5509 Object[] asyncEndArgs)
5511 // This is when we have a list of args associated with EndFoo(), and
5512 // we want to size it to a list of args associated with Foo();
5514 Object[] args = new Object[syncMethod.Parameters.Length];
5516 int[] outRefArgMap = syncMethod.OutRefArgMap;
5518 for (int co = 0; co < outRefArgMap.Length; co++)
5520 args[outRefArgMap[co]] = asyncEndArgs[co];
5524 } // ExpandAsyncEndArgsToSyncArgs
5526 } // class ArgMapper
5528 internal class ErrorMessage: IMethodCallMessage
5532 public IDictionary Properties
5534 [System.Security.SecurityCritical] // auto-generated
5541 [System.Security.SecurityCritical] // auto-generated
5542 get{ return m_URI; }
5545 public String MethodName
5547 [System.Security.SecurityCritical] // auto-generated
5548 get{ return m_MethodName; }
5551 public String TypeName
5553 [System.Security.SecurityCritical] // auto-generated
5554 get{ return m_TypeName; }
5557 public Object MethodSignature
5559 [System.Security.SecurityCritical] // auto-generated
5560 get { return m_MethodSignature; }
5563 public MethodBase MethodBase
5565 [System.Security.SecurityCritical] // auto-generated
5566 get { return null; }
5571 [System.Security.SecurityCritical] // auto-generated
5572 get { return m_ArgCount;}
5575 [System.Security.SecurityCritical] // auto-generated
5576 public String GetArgName(int index) { return m_ArgName; }
5577 [System.Security.SecurityCritical] // auto-generated
5578 public Object GetArg(int argNum) { return null;}
5579 public Object[] Args
5581 [System.Security.SecurityCritical] // auto-generated
5585 public bool HasVarArgs
5587 [System.Security.SecurityCritical] // auto-generated
5588 get { return false;}
5592 // IMethodCallMessage
5593 public int InArgCount
5595 [System.Security.SecurityCritical] // auto-generated
5596 get { return m_ArgCount;}
5598 [System.Security.SecurityCritical] // auto-generated
5599 public String GetInArgName(int index) { return null; }
5600 [System.Security.SecurityCritical] // auto-generated
5601 public Object GetInArg(int argNum) { return null;}
5602 public Object[] InArgs
5604 [System.Security.SecurityCritical] // auto-generated
5605 get { return null; }
5607 public LogicalCallContext LogicalCallContext
5609 [System.Security.SecurityCritical] // auto-generated
5610 get { return null; }
5613 String m_URI = "Exception";
5614 String m_MethodName = "Unknown";
5615 String m_TypeName = "Unknown";
5616 Object m_MethodSignature = null;
5618 String m_ArgName = "Unknown";
5623 //+================================================================================
5625 // Synopsis: Message wrapper used as base class for all exposed message wrappers.
5626 // This is needed so that we can extract the identity object from a custom message.
5628 //-================================================================================
5630 [System.Security.SecurityCritical] // auto-generated
5631 [System.Runtime.InteropServices.ComVisible(true)]
5632 public class InternalMessageWrapper
5635 protected IMessage WrappedMessage;
5638 public InternalMessageWrapper(IMessage msg)
5640 WrappedMessage = msg;
5641 } // InternalMessageWrapper
5643 [System.Security.SecurityCritical] // auto-generated
5644 internal Object GetIdentityObject()
5646 IInternalMessage iim = WrappedMessage as IInternalMessage;
5649 return iim.IdentityObject;
5653 InternalMessageWrapper imw = WrappedMessage as InternalMessageWrapper;
5656 return imw.GetIdentityObject();
5663 } // GetIdentityObject
5665 [System.Security.SecurityCritical] // auto-generated
5666 internal Object GetServerIdentityObject()
5668 IInternalMessage iim = WrappedMessage as IInternalMessage;
5671 return iim.ServerIdentityObject;
5675 InternalMessageWrapper imw = WrappedMessage as InternalMessageWrapper;
5678 return imw.GetServerIdentityObject();
5685 } // GetServerIdentityObject
5687 } // class InternalMessageWrapper
5691 //+================================================================================
5693 // Synopsis: Message wrapper used for creating custom method call messages.
5695 //-================================================================================
5697 [System.Security.SecurityCritical] // auto-generated_required
5698 [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.Infrastructure)]
5699 [System.Runtime.InteropServices.ComVisible(true)]
5700 public class MethodCallMessageWrapper : InternalMessageWrapper, IMethodCallMessage
5702 // we need to overload the dictionary to delegate special values to this class
5703 private class MCMWrapperDictionary : Hashtable
5705 private IMethodCallMessage _mcmsg; // pointer to this message object
5706 private IDictionary _idict; // point to contained message's dictionary
5708 public MCMWrapperDictionary(IMethodCallMessage msg, IDictionary idict)
5714 public override Object this[Object key]
5716 [System.Security.SecuritySafeCritical] // overrides transparent public member
5719 System.String strKey = key as System.String;
5724 case "__Uri": return _mcmsg.Uri;
5725 case "__MethodName": return _mcmsg.MethodName;
5726 case "__MethodSignature": return _mcmsg.MethodSignature;
5727 case "__TypeName": return _mcmsg.TypeName;
5728 case "__Args": return _mcmsg.Args;
5733 [System.Security.SecuritySafeCritical] // overrides transparent public member
5736 System.String strKey = key as System.String;
5741 case "__MethodName":
5742 case "__MethodSignature":
5745 throw new RemotingException(
5746 Environment.GetResourceString("Remoting_Default"));
5748 _idict[key] = value;
5752 } // class MCMWrapperDictionary
5755 IMethodCallMessage _msg;
5756 IDictionary _properties;
5757 ArgMapper _argMapper = null;
5762 public MethodCallMessageWrapper(IMethodCallMessage msg) : base(msg)
5766 } // MethodCallMessageWrapper
5769 // IMethodMessage implementation
5772 public virtual String Uri
5774 [System.Security.SecurityCritical]
5781 _msg.Properties[Message.UriKey] = value;
5786 public virtual String MethodName
5788 [System.Security.SecurityCritical]
5789 get { return _msg.MethodName; }
5792 public virtual String TypeName
5794 [System.Security.SecurityCritical]
5795 get { return _msg.TypeName; }
5798 public virtual Object MethodSignature
5800 [System.Security.SecurityCritical]
5801 get { return _msg.MethodSignature; }
5804 public virtual LogicalCallContext LogicalCallContext
5806 [System.Security.SecurityCritical]
5807 get { return _msg.LogicalCallContext; }
5810 public virtual MethodBase MethodBase
5812 [System.Security.SecurityCritical]
5813 get { return _msg.MethodBase; }
5817 public virtual int ArgCount
5819 [System.Security.SecurityCritical]
5823 return _args.Length;
5829 [System.Security.SecurityCritical]
5830 public virtual String GetArgName(int index) { return _msg.GetArgName(index); }
5832 [System.Security.SecurityCritical]
5833 public virtual Object GetArg(int argNum) { return _args[argNum]; }
5835 public virtual Object[] Args
5837 [System.Security.SecurityCritical]
5838 get { return _args; }
5839 set { _args = value; }
5843 public virtual bool HasVarArgs
5845 [System.Security.SecurityCritical]
5846 get { return _msg.HasVarArgs; }
5849 // end of IMethodMessage implementation
5852 // IMethodCallMessage implementation
5853 // (We cannot simply delegate to the internal message
5854 // since we override the definition of Args and create our own array
5855 // which can be modified.)
5857 public virtual int InArgCount
5859 [System.Security.SecurityCritical]
5862 if (_argMapper == null) _argMapper = new ArgMapper(this, false);
5863 return _argMapper.ArgCount;
5868 [System.Security.SecurityCritical]
5869 public virtual Object GetInArg(int argNum)
5871 if (_argMapper == null) _argMapper = new ArgMapper(this, false);
5872 return _argMapper.GetArg(argNum);
5876 [System.Security.SecurityCritical]
5877 public virtual String GetInArgName(int index)
5879 if (_argMapper == null) _argMapper = new ArgMapper(this, false);
5880 return _argMapper.GetArgName(index);
5884 public virtual Object[] InArgs
5886 [System.Security.SecurityCritical]
5889 if (_argMapper == null) _argMapper = new ArgMapper(this, false);
5890 return _argMapper.Args;
5894 // end of IMethodCallMessage implementation
5898 public virtual IDictionary Properties
5900 [System.Security.SecurityCritical]
5903 if (_properties == null)
5904 _properties = new MCMWrapperDictionary(this, _msg.Properties);
5909 } // class MethodCallMessageWrapper
5913 //+================================================================================
5915 // Synopsis: Message wrapper used for creating custom method return messages.
5917 //-================================================================================
5919 [System.Security.SecurityCritical] // auto-generated_required
5920 [SecurityPermissionAttribute(SecurityAction.InheritanceDemand, Flags=SecurityPermissionFlag.Infrastructure)]
5921 [System.Runtime.InteropServices.ComVisible(true)]
5922 public class MethodReturnMessageWrapper : InternalMessageWrapper, IMethodReturnMessage
5924 // we need to overload the dictionary to delegate special values to this class
5925 private class MRMWrapperDictionary : Hashtable
5927 private IMethodReturnMessage _mrmsg; // pointer to this message object
5928 private IDictionary _idict; // point to contained message's dictionary
5930 public MRMWrapperDictionary(IMethodReturnMessage msg, IDictionary idict)
5936 public override Object this[Object key]
5938 [System.Security.SecuritySafeCritical] // overrides transparent public member
5941 System.String strKey = key as System.String;
5946 case "__Uri": return _mrmsg.Uri;
5947 case "__MethodName": return _mrmsg.MethodName;
5948 case "__MethodSignature": return _mrmsg.MethodSignature;
5949 case "__TypeName": return _mrmsg.TypeName;
5950 case "__Return": return _mrmsg.ReturnValue;
5951 case "__OutArgs": return _mrmsg.OutArgs;
5956 [System.Security.SecuritySafeCritical] // overrides transparent public member
5959 System.String strKey = key as System.String;
5964 case "__MethodName":
5965 case "__MethodSignature":
5969 throw new RemotingException(
5970 Environment.GetResourceString("Remoting_Default"));
5972 _idict[key] = value;
5976 } // class MCMWrapperDictionary
5979 IMethodReturnMessage _msg;
5980 IDictionary _properties;
5981 ArgMapper _argMapper = null;
5982 Object[] _args = null;
5983 Object _returnValue = null;
5984 Exception _exception = null;
5988 public MethodReturnMessageWrapper(IMethodReturnMessage msg) : base(msg)
5992 _returnValue = _msg.ReturnValue; // be careful if you decide to lazily assign _returnValue
5993 // since the return value might actually be null
5994 _exception = _msg.Exception; // (same thing as above goes for _exception)
5995 } // MethodReturnMessageWrapper
5998 // IMethodMessage implementation
6003 [System.Security.SecurityCritical]
6011 _msg.Properties[Message.UriKey] = value;
6016 public virtual String MethodName
6018 [System.Security.SecurityCritical]
6019 get { return _msg.MethodName; }
6022 public virtual String TypeName
6024 [System.Security.SecurityCritical]
6025 get { return _msg.TypeName; }
6028 public virtual Object MethodSignature
6030 [System.Security.SecurityCritical]
6031 get { return _msg.MethodSignature; }
6034 public virtual LogicalCallContext LogicalCallContext
6036 [System.Security.SecurityCritical]
6037 get { return _msg.LogicalCallContext; }
6040 public virtual MethodBase MethodBase
6042 [System.Security.SecurityCritical]
6043 get { return _msg.MethodBase; }
6047 public virtual int ArgCount
6049 [System.Security.SecurityCritical]
6053 return _args.Length;
6060 [System.Security.SecurityCritical]
6061 public virtual String GetArgName(int index) { return _msg.GetArgName(index); }
6063 [System.Security.SecurityCritical]
6064 public virtual Object GetArg(int argNum) { return _args[argNum]; }
6066 public virtual Object[] Args
6068 [System.Security.SecurityCritical]
6069 get { return _args; }
6070 set { _args = value; }
6074 public virtual bool HasVarArgs
6076 [System.Security.SecurityCritical]
6077 get { return _msg.HasVarArgs; }
6080 // end of IMethodMessage implementation
6083 // IMethodReturnMessage implementation
6084 // (We cannot simply delegate to the internal message
6085 // since we override the definition of Args and create our own array
6086 // which can be modified.)
6088 public virtual int OutArgCount
6090 [System.Security.SecurityCritical]
6093 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
6094 return _argMapper.ArgCount;
6099 [System.Security.SecurityCritical]
6100 public virtual Object GetOutArg(int argNum)
6102 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
6103 return _argMapper.GetArg(argNum);
6107 [System.Security.SecurityCritical]
6108 public virtual String GetOutArgName(int index)
6110 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
6111 return _argMapper.GetArgName(index);
6115 public virtual Object[] OutArgs
6117 [System.Security.SecurityCritical]
6120 if (_argMapper == null) _argMapper = new ArgMapper(this, true);
6121 return _argMapper.Args;
6126 public virtual Exception Exception
6128 [System.Security.SecurityCritical]
6129 get { return _exception; }
6130 set { _exception = value; }
6134 public virtual Object ReturnValue
6136 [System.Security.SecurityCritical]
6137 get { return _returnValue; }
6138 set { _returnValue = value; }
6141 // end of IMethodReturnMessage implementation
6145 public virtual IDictionary Properties
6147 [System.Security.SecurityCritical]
6150 if (_properties == null)
6151 _properties = new MRMWrapperDictionary(this, _msg.Properties);
6157 } // class MethodReturnMessageWrapper
6159 } // namespace Remoting