public static void PreLoad(Type type) { if (type == null) { throw new ArgumentNullException("type"); } if (!(type is RuntimeType)) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); } foreach (MethodInfo info in type.GetMethods()) { RegisterSoapActionForMethodBase(info); } SoapTypeAttribute cachedSoapAttribute = (SoapTypeAttribute)InternalRemotingServices.GetCachedSoapAttribute(type); if (cachedSoapAttribute.IsInteropXmlElement()) { RegisterInteropXmlElement(cachedSoapAttribute.XmlElementName, cachedSoapAttribute.XmlNamespace, type); } if (cachedSoapAttribute.IsInteropXmlType()) { RegisterInteropXmlType(cachedSoapAttribute.XmlTypeName, cachedSoapAttribute.XmlTypeNamespace, type); } int num = 0; XmlToFieldTypeMap map = new XmlToFieldTypeMap(); foreach (FieldInfo info2 in type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { SoapFieldAttribute attribute2 = (SoapFieldAttribute)InternalRemotingServices.GetCachedSoapAttribute(info2); if (attribute2.IsInteropXmlElement()) { string xmlElementName = attribute2.XmlElementName; string xmlNamespace = attribute2.XmlNamespace; if (attribute2.UseAttribute) { map.AddXmlAttribute(info2.FieldType, info2.Name, xmlElementName, xmlNamespace); } else { map.AddXmlElement(info2.FieldType, info2.Name, xmlElementName, xmlNamespace); } num++; } } if (num > 0) { _xmlToFieldTypeMap[type] = map; } }
public static SoapAttribute GetCachedSoapAttribute(object reflectionObject) { MemberInfo mi = reflectionObject as MemberInfo; RuntimeParameterInfo reflectionObject1 = reflectionObject as RuntimeParameterInfo; if (mi != (MemberInfo)null) { return(InternalRemotingServices.GetReflectionCachedData(mi).GetSoapAttribute()); } if (reflectionObject1 != null) { return(InternalRemotingServices.GetReflectionCachedData(reflectionObject1).GetSoapAttribute()); } return((SoapAttribute)null); }
public static bool GetXmlTypeForInteropType(Type type, out string xmlType, out string xmlTypeNamespace) { SoapTypeAttribute att = (SoapTypeAttribute)InternalRemotingServices.GetCachedSoapAttribute(type); if (!att.IsInteropXmlType) { xmlType = null; xmlTypeNamespace = null; return(false); } xmlType = att.XmlTypeName; xmlTypeNamespace = att.XmlTypeNamespace; return(true); }
static string InternalGetSoapAction(MethodBase mb) { lock (_soapActions.SyncRoot) { string action = (string)_soapActions [mb]; if (action == null) { SoapMethodAttribute att = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); action = att.SoapAction; _soapActions [mb] = action; _soapActionsMethods [action] = mb; } return(action); } }
internal static ActivatedClientTypeEntry IsRemotelyActivatedClientType(RuntimeType svrType) { RemotingTypeCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(svrType); string simpleAssemblyName = reflectionCachedData.SimpleAssemblyName; ActivatedClientTypeEntry entry = Info.QueryRemoteActivate(svrType.FullName, simpleAssemblyName); if (entry == null) { string assemblyName = reflectionCachedData.AssemblyName; entry = Info.QueryRemoteActivate(svrType.FullName, assemblyName); if (entry == null) { entry = Info.QueryRemoteActivate(svrType.Name, simpleAssemblyName); } } return(entry); }
private static string InternalGetSoapAction(MethodBase mb) { object syncRoot = SoapServices._soapActions.SyncRoot; string result; lock (syncRoot) { string text = (string)SoapServices._soapActions[mb]; if (text == null) { SoapMethodAttribute soapMethodAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); text = soapMethodAttribute.SoapAction; SoapServices._soapActions[mb] = text; SoapServices._soapActionsMethods[text] = mb; } result = text; } return(result); }
// Get the SOAP action associated with a method. public static String GetSoapActionFromMethodBase(MethodBase mb) { // See if we have a registered action first. lock (typeof(SoapServices)) { if (methodToAction != null) { String temp = (String)(methodToAction[mb]); if (temp != null) { return(temp); } } } // Get the action from the method itself. return(((SoapMethodAttribute) InternalRemotingServices.GetCachedSoapAttribute(mb)) .SoapAction); }
public static bool GetXmlTypeForInteropType(Type type, out string xmlType, out string xmlTypeNamespace) { SoapServices.XmlEntry xmlEntry = (SoapServices.XmlEntry)SoapServices._interopTypeToXmlType[type]; if (xmlEntry != null) { xmlType = xmlEntry.Name; xmlTypeNamespace = xmlEntry.Namespace; return(true); } SoapTypeAttribute soapTypeAttribute = (SoapTypeAttribute)InternalRemotingServices.GetCachedSoapAttribute(type); if (soapTypeAttribute.IsInteropXmlType()) { xmlType = soapTypeAttribute.XmlTypeName; xmlTypeNamespace = soapTypeAttribute.XmlTypeNamespace; return(true); } xmlType = null; xmlTypeNamespace = null; return(false); }
public static bool GetXmlElementForInteropType(Type type, out string xmlElement, out string xmlNamespace) { XmlEntry entry = (XmlEntry)_interopTypeToXmlElement[type]; if (entry != null) { xmlElement = entry.Name; xmlNamespace = entry.Namespace; return(true); } SoapTypeAttribute cachedSoapAttribute = (SoapTypeAttribute)InternalRemotingServices.GetCachedSoapAttribute(type); if (cachedSoapAttribute.IsInteropXmlElement()) { xmlElement = cachedSoapAttribute.XmlElementName; xmlNamespace = cachedSoapAttribute.XmlNamespace; return(true); } xmlElement = null; xmlNamespace = null; return(false); }
// Get the namespace to use for a method response. public static String GetXmlNamespaceForMethodResponse(MethodBase mb) { return(((SoapMethodAttribute) InternalRemotingServices.GetCachedSoapAttribute(mb)) .ResponseXmlNamespace); }
internal void Init(object o, Identity idObj, RuntimeType requestedType) { this.uri = idObj.URI; MarshalByRefObject tporObject = idObj.TPOrObject; RuntimeType runtimeType; if (!RemotingServices.IsTransparentProxy(tporObject)) { runtimeType = (RuntimeType)tporObject.GetType(); } else { runtimeType = (RuntimeType)RemotingServices.GetRealProxy(tporObject).GetProxiedType(); } RuntimeType runtimeType2 = (null == requestedType) ? runtimeType : requestedType; if (null != requestedType && !requestedType.IsAssignableFrom(runtimeType) && !typeof(IMessageSink).IsAssignableFrom(runtimeType)) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidRequestedType"), requestedType.ToString())); } if (runtimeType.IsCOMObject) { DynamicTypeInfo dynamicTypeInfo = new DynamicTypeInfo(runtimeType2); this.TypeInfo = dynamicTypeInfo; } else { RemotingTypeCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(runtimeType2); this.TypeInfo = reflectionCachedData.TypeInfo; } if (!idObj.IsWellKnown()) { this.EnvoyInfo = System.Runtime.Remoting.EnvoyInfo.CreateEnvoyInfo(idObj as ServerIdentity); IChannelInfo channelInfo = new ChannelInfo(); if (o is AppDomain) { object[] channelData = channelInfo.ChannelData; int num = channelData.Length; object[] array = new object[num]; Array.Copy(channelData, array, num); for (int i = 0; i < num; i++) { if (!(array[i] is CrossAppDomainData)) { array[i] = null; } } channelInfo.ChannelData = array; } this.ChannelInfo = channelInfo; if (runtimeType.HasProxyAttribute) { this.SetHasProxyAttribute(); } } else { this.SetWellKnown(); } if (ObjRef.ShouldUseUrlObjRef()) { if (this.IsWellKnown()) { this.SetObjRefLite(); return; } string text = ChannelServices.FindFirstHttpUrlForObject(this.URI); if (text != null) { this.URI = text; this.SetObjRefLite(); } } }
public static string GetXmlNamespaceForMethodCall(MethodBase mb) { return(InternalRemotingServices.GetCachedSoapAttribute((object)mb).XmlNamespace); }
public static string GetSoapActionFromMethodBase(MethodBase mb) { return((string)SoapServices._methodBaseToSoapAction[(object)mb] ?? ((SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute((object)mb)).SoapAction); }
public static bool IsSoapActionValidForMethodBase(string soapAction, MethodBase mb) { if (mb == (MethodBase)null) { throw new ArgumentNullException("mb"); } if ((int)soapAction[0] == 34) { string str = soapAction; int index = str.Length - 1; if ((int)str[index] == 34) { soapAction = soapAction.Substring(1, soapAction.Length - 2); } } if (string.CompareOrdinal(((SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute((object)mb)).SoapAction, soapAction) == 0) { return(true); } string strA = (string)SoapServices._methodBaseToSoapAction[(object)mb]; if (strA != null && string.CompareOrdinal(strA, soapAction) == 0) { return(true); } string[] strArray = soapAction.Split('#'); if (strArray.Length != 2) { return(false); } bool assemblyIncluded; string soapActionNamespace = XmlNamespaceEncoder.GetTypeNameForSoapActionNamespace(strArray[0], out assemblyIncluded); if (soapActionNamespace == null) { return(false); } string str1 = strArray[1]; RuntimeMethodInfo runtimeMethodInfo = mb as RuntimeMethodInfo; RuntimeConstructorInfo runtimeConstructorInfo = mb as RuntimeConstructorInfo; RuntimeModule runtimeModule; if ((MethodInfo)runtimeMethodInfo != (MethodInfo)null) { runtimeModule = runtimeMethodInfo.GetRuntimeModule(); } else { if (!((ConstructorInfo)runtimeConstructorInfo != (ConstructorInfo)null)) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeReflectionObject")); } runtimeModule = runtimeConstructorInfo.GetRuntimeModule(); } string str2 = mb.DeclaringType.FullName; if (assemblyIncluded) { str2 = str2 + ", " + runtimeModule.GetRuntimeAssembly().GetSimpleName(); } if (str2.Equals(soapActionNamespace)) { return(mb.Name.Equals(str1)); } return(false); }
[System.Security.SecurityCritical] // auto-generated public static void PreLoad(Type type) { if (type == null) { throw new ArgumentNullException("type"); } Contract.EndContractBlock(); if (!(type is RuntimeType)) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); } // register soap action values MethodInfo[] methods = type.GetMethods(); foreach (MethodInfo mi in methods) { // This will only add an entry to the table if SoapAction was explicitly set // on the SoapMethodAttribute. RegisterSoapActionForMethodBase(mi); } // register interop xml elements and types if specified SoapTypeAttribute attr = (SoapTypeAttribute) InternalRemotingServices.GetCachedSoapAttribute(type); if (attr.IsInteropXmlElement()) { RegisterInteropXmlElement(attr.XmlElementName, attr.XmlNamespace, type); } if (attr.IsInteropXmlType()) { RegisterInteropXmlType(attr.XmlTypeName, attr.XmlTypeNamespace, type); } // construct field maps for mapping xml elements and attributes back to // the correct type int mapCount = 0; XmlToFieldTypeMap map = new XmlToFieldTypeMap(); foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly)) { SoapFieldAttribute fieldAttr = (SoapFieldAttribute) InternalRemotingServices.GetCachedSoapAttribute(field); if (fieldAttr.IsInteropXmlElement()) { String xmlName = fieldAttr.XmlElementName; String xmlNamespace = fieldAttr.XmlNamespace; if (fieldAttr.UseAttribute) { map.AddXmlAttribute(field.FieldType, field.Name, xmlName, xmlNamespace); } else { map.AddXmlElement(field.FieldType, field.Name, xmlName, xmlNamespace); } mapCount++; } } // foreach field // add field map if there is more than one entry if (mapCount > 0) { _xmlToFieldTypeMap[type] = map; } } // PreLoad
public static string GetXmlNamespaceForMethodCall(MethodBase mb) { SoapMethodAttribute soapMethodAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); return(soapMethodAttribute.XmlNamespace); }
internal void Init(object o, Identity idObj, RuntimeType requestedType) { this.uri = idObj.URI; MarshalByRefObject tPOrObject = idObj.TPOrObject; RuntimeType c = null; if (!RemotingServices.IsTransparentProxy(tPOrObject)) { c = (RuntimeType)tPOrObject.GetType(); } else { c = (RuntimeType)RemotingServices.GetRealProxy(tPOrObject).GetProxiedType(); } RuntimeType typeOfObj = (null == requestedType) ? c : requestedType; if (((null != requestedType) && !requestedType.IsAssignableFrom(c)) && !typeof(IMessageSink).IsAssignableFrom(c)) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidRequestedType"), new object[] { requestedType.ToString() })); } if (c.IsCOMObject) { DynamicTypeInfo info = new DynamicTypeInfo(typeOfObj); this.TypeInfo = info; } else { RemotingTypeCachedData reflectionCachedData = InternalRemotingServices.GetReflectionCachedData(typeOfObj); this.TypeInfo = reflectionCachedData.TypeInfo; } if (!idObj.IsWellKnown()) { this.EnvoyInfo = System.Runtime.Remoting.EnvoyInfo.CreateEnvoyInfo(idObj as ServerIdentity); IChannelInfo info2 = new System.Runtime.Remoting.ChannelInfo(); if (o is AppDomain) { object[] channelData = info2.ChannelData; int length = channelData.Length; object[] destinationArray = new object[length]; Array.Copy(channelData, destinationArray, length); for (int i = 0; i < length; i++) { if (!(destinationArray[i] is CrossAppDomainData)) { destinationArray[i] = null; } } info2.ChannelData = destinationArray; } this.ChannelInfo = info2; if (c.HasProxyAttribute) { this.SetHasProxyAttribute(); } } else { this.SetWellKnown(); } if (ShouldUseUrlObjRef()) { if (this.IsWellKnown()) { this.SetObjRefLite(); } else { string str = ChannelServices.FindFirstHttpUrlForObject(this.URI); if (str != null) { this.URI = str; this.SetObjRefLite(); } } } }
// // internal void Init(Identity idObj, Type requestedType) { Message.DebugOut("RemotingServices::FillObjRef: IN"); BCLDebug.Assert(idObj != null, "idObj != null"); // Set the URI of the object to be marshaled URI = idObj.URI; // Figure out the type MarshalByRefObject obj = idObj.TPOrObject; BCLDebug.Assert(null != obj, "Identity not setup correctly"); // Get the type of the object Type serverType = null; if (!RemotingServices.IsTransparentProxy(obj)) { serverType = obj.GetType(); } else { serverType = RemotingServices.GetRealProxy(obj).GetProxiedType(); } Type typeOfObj = (null == requestedType ? serverType : requestedType); // Make sure that the server and requested types are compatible // (except for objects that implement IMessageSink, since we // just hand off the message instead of invoking the proxy) if ((null != requestedType) && !requestedType.IsAssignableFrom(serverType) && (!typeof(IMessageSink).IsAssignableFrom(serverType))) { throw new RemotingException( String.Format( Environment.GetResourceString( "Remoting_InvalidRequestedType"), requestedType.ToString()));; } // Create the type info if (serverType.IsCOMObject) { // __ComObjects need dynamic TypeInfo DynamicTypeInfo dt = new DynamicTypeInfo(typeOfObj); TypeInfo = (IRemotingTypeInfo)dt; } else { RemotingTypeCachedData cache = (RemotingTypeCachedData) InternalRemotingServices.GetReflectionCachedData(typeOfObj); TypeInfo = (IRemotingTypeInfo)cache.TypeInfo; } if (!idObj.IsWellKnown()) { // Create the envoy info EnvoyInfo = System.Runtime.Remoting.EnvoyInfo.CreateEnvoyInfo(idObj as ServerIdentity); // Create the channel info ChannelInfo = (IChannelInfo) new ChannelInfo(); if (serverType.HasProxyAttribute) { SetHasProxyAttribute(); } } else { SetWellKnown(); } // See if we should and can use a url obj ref? if (ShouldUseUrlObjRef()) { if (IsWellKnown()) { // full uri already supplied. SetObjRefLite(); } else { String httpUri = ChannelServices.FindFirstHttpUrlForObject(URI); if (httpUri != null) { URI = httpUri; SetObjRefLite(); } } } } // Init
} // GetSoapActionFromMethodBase /// <include file='doc\Soap.uex' path='docs/doc[@for="SoapServices.IsSoapActionValidForMethodBase"]/*' /> public static bool IsSoapActionValidForMethodBase(String soapAction, MethodBase mb) { // remove quotation marks if present if ((soapAction[0] == '"') && (soapAction[soapAction.Length - 1] == '"')) { soapAction = soapAction.Substring(1, soapAction.Length - 2); } // compare this to the soapAction on the method base SoapMethodAttribute attr = (SoapMethodAttribute) InternalRemotingServices.GetCachedSoapAttribute(mb); if (String.CompareOrdinal(attr.SoapAction, soapAction) == 0) { return(true); } // check to see if a soap action value is registered for this String registeredSoapAction = (String)_methodBaseToSoapAction[mb]; if (registeredSoapAction != null) { if (String.CompareOrdinal(registeredSoapAction, soapAction) == 0) { return(true); } } // otherwise, parse SOAPAction and verify String typeName, methodName; String[] parts = soapAction.Split(new char[1] { '#' }); if (parts.Length == 2) { bool assemblyIncluded; typeName = XmlNamespaceEncoder.GetTypeNameForSoapActionNamespace( parts[0], out assemblyIncluded); if (typeName == null) { return(false); } methodName = parts[1]; // compare to values of method base (FUTURE: Use more direct method for this) Type type = mb.DeclaringType; String actualTypeName = type.FullName; if (assemblyIncluded) { actualTypeName += ", " + type.Module.Assembly.nGetSimpleName(); } // return true if type and method name are the same return(actualTypeName.Equals(typeName) && mb.Name.Equals(methodName)); } else { return(false); } } // IsSoapActionValidForMethodBase
[System.Security.SecurityCritical] // auto-generated public static bool IsSoapActionValidForMethodBase(String soapAction, MethodBase mb) { if (mb == null) { throw new ArgumentNullException("mb"); } // remove quotation marks if present if ((soapAction[0] == '"') && (soapAction[soapAction.Length - 1] == '"')) { soapAction = soapAction.Substring(1, soapAction.Length - 2); } // compare this to the soapAction on the method base SoapMethodAttribute attr = (SoapMethodAttribute) InternalRemotingServices.GetCachedSoapAttribute(mb); if (String.CompareOrdinal(attr.SoapAction, soapAction) == 0) { return(true); } // check to see if a soap action value is registered for this String registeredSoapAction = (String)_methodBaseToSoapAction[mb]; if (registeredSoapAction != null) { if (String.CompareOrdinal(registeredSoapAction, soapAction) == 0) { return(true); } } // otherwise, parse SOAPAction and verify String typeName, methodName; String[] parts = soapAction.Split(new char[1] { '#' }); if (parts.Length == 2) { bool assemblyIncluded; typeName = XmlNamespaceEncoder.GetTypeNameForSoapActionNamespace( parts[0], out assemblyIncluded); if (typeName == null) { return(false); } methodName = parts[1]; // compare to values of method base ( RuntimeMethodInfo rmi = mb as RuntimeMethodInfo; RuntimeConstructorInfo rci = mb as RuntimeConstructorInfo; RuntimeModule rtModule; if (rmi != null) { rtModule = rmi.GetRuntimeModule(); } else if (rci != null) { rtModule = rci.GetRuntimeModule(); } else { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeReflectionObject")); } String actualTypeName = mb.DeclaringType.FullName; if (assemblyIncluded) { actualTypeName += ", " + rtModule.GetRuntimeAssembly().GetSimpleName(); } // return true if type and method name are the same return(actualTypeName.Equals(typeName) && mb.Name.Equals(methodName)); } else { return(false); } } // IsSoapActionValidForMethodBase
// Determine if a SOAP action is valid for a method. public static bool IsSoapActionValidForMethodBase (String soapAction, MethodBase mb) { SoapMethodAttribute mattr; int index, index2; String typeName; String mbTypeName; String assembly; bool hasAssembly; // Remove quotes from the action name. if (soapAction[0] == '"' && soapAction.EndsWith("\"")) { soapAction = soapAction.Substring (1, soapAction.Length - 2); } // If the action matches the attribute, then return true. mattr = (SoapMethodAttribute) InternalRemotingServices.GetCachedSoapAttribute(mb); if (mattr.SoapAction == soapAction) { return(true); } // Determine if the action matches the one registered // with the method. lock (typeof(SoapServices)) { if (methodToAction != null) { String temp = (String)(methodToAction[mb]); if (temp != null && temp == soapAction) { return(true); } } } // Pull apart the action and check its components. index = soapAction.IndexOf('#'); if (index != -1) { typeName = ExtractTypeName (soapAction.Substring(0, index), out hasAssembly); if (typeName != null) { if (hasAssembly) { assembly = mb.DeclaringType.Module .Assembly.FullName; index2 = assembly.IndexOf(','); if (index2 != -1) { assembly = assembly.Substring(0, index2); } mbTypeName = mb.DeclaringType.FullName + ", " + assembly; } else { mbTypeName = mb.DeclaringType.FullName; } if (typeName == mbTypeName) { return(mb.Name == soapAction.Substring(index + 1)); } } } // The action string is not valid. return(false); }
public static bool IsSoapActionValidForMethodBase(string soapAction, MethodBase mb) { if (mb == null) { throw new ArgumentNullException("mb"); } if (soapAction[0] == '"' && soapAction[soapAction.Length - 1] == '"') { soapAction = soapAction.Substring(1, soapAction.Length - 2); } SoapMethodAttribute soapMethodAttribute = (SoapMethodAttribute)InternalRemotingServices.GetCachedSoapAttribute(mb); if (string.CompareOrdinal(soapMethodAttribute.SoapAction, soapAction) == 0) { return(true); } string text = (string)SoapServices._methodBaseToSoapAction[mb]; if (text != null && string.CompareOrdinal(text, soapAction) == 0) { return(true); } string[] array = soapAction.Split(new char[] { '#' }); if (array.Length != 2) { return(false); } bool flag; string typeNameForSoapActionNamespace = XmlNamespaceEncoder.GetTypeNameForSoapActionNamespace(array[0], out flag); if (typeNameForSoapActionNamespace == null) { return(false); } string value = array[1]; RuntimeMethodInfo runtimeMethodInfo = mb as RuntimeMethodInfo; RuntimeConstructorInfo runtimeConstructorInfo = mb as RuntimeConstructorInfo; RuntimeModule runtimeModule; if (runtimeMethodInfo != null) { runtimeModule = runtimeMethodInfo.GetRuntimeModule(); } else { if (!(runtimeConstructorInfo != null)) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeReflectionObject")); } runtimeModule = runtimeConstructorInfo.GetRuntimeModule(); } string text2 = mb.DeclaringType.FullName; if (flag) { text2 = text2 + ", " + runtimeModule.GetRuntimeAssembly().GetSimpleName(); } return(text2.Equals(typeNameForSoapActionNamespace) && mb.Name.Equals(value)); }
// // internal void Init(Object o, Identity idObj, Type requestedType) { Message.DebugOut("RemotingServices::FillObjRef: IN"); BCLDebug.Assert(idObj != null, "idObj != null"); // Set the URI of the object to be marshaled uri = idObj.URI; // Figure out the type MarshalByRefObject obj = idObj.TPOrObject; BCLDebug.Assert(null != obj, "Identity not setup correctly"); // Get the type of the object Type serverType = null; if (!RemotingServices.IsTransparentProxy(obj)) { serverType = obj.GetType(); } else { serverType = RemotingServices.GetRealProxy(obj).GetProxiedType(); } Type typeOfObj = (null == requestedType ? serverType : requestedType); // Make sure that the server and requested types are compatible // (except for objects that implement IMessageSink, since we // just hand off the message instead of invoking the proxy) if ((null != requestedType) && !requestedType.IsAssignableFrom(serverType) && (!typeof(IMessageSink).IsAssignableFrom(serverType))) { throw new RemotingException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString( "Remoting_InvalidRequestedType"), requestedType.ToString()));; } { RemotingTypeCachedData cache = (RemotingTypeCachedData) InternalRemotingServices.GetReflectionCachedData(typeOfObj); TypeInfo = (IRemotingTypeInfo)cache.TypeInfo; } if (!idObj.IsWellKnown()) { // Create the envoy info EnvoyInfo = System.Runtime.Remoting.EnvoyInfo.CreateEnvoyInfo(idObj as ServerIdentity); // Create the channel info IChannelInfo chan = (IChannelInfo) new ChannelInfo(); // Make sure the channelInfo only has x-appdomain data since the objref is agile while other // channelData might not be and regardless this data is useless for an appdomain proxy if (o is AppDomain) { Object[] channelData = chan.ChannelData; int channelDataLength = channelData.Length; Object[] newChannelData = new Object[channelDataLength]; Array.Copy(channelData, newChannelData, channelDataLength); for (int i = 0; i < channelDataLength; i++) { if (!(newChannelData[i] is CrossAppDomainData)) { newChannelData[i] = null; } } chan.ChannelData = newChannelData; } ChannelInfo = chan; if (serverType.HasProxyAttribute) { SetHasProxyAttribute(); } } else { SetWellKnown(); } // See if we should and can use a url obj ref? if (ShouldUseUrlObjRef()) { if (IsWellKnown()) { // full uri already supplied. SetObjRefLite(); } else { String httpUri = ChannelServices.FindFirstHttpUrlForObject(URI); if (httpUri != null) { URI = httpUri; SetObjRefLite(); } } } } // Init
internal void Init(object o, Identity idObj, RuntimeType requestedType) { this.uri = idObj.URI; MarshalByRefObject tpOrObject = idObj.TPOrObject; RuntimeType runtimeType1 = RemotingServices.IsTransparentProxy((object)tpOrObject) ? (RuntimeType)RemotingServices.GetRealProxy((object)tpOrObject).GetProxiedType() : (RuntimeType)tpOrObject.GetType(); RuntimeType runtimeType2 = (RuntimeType)null == requestedType ? runtimeType1 : requestedType; if ((RuntimeType)null != requestedType && !requestedType.IsAssignableFrom((System.Reflection.TypeInfo)runtimeType1) && !typeof(IMessageSink).IsAssignableFrom((Type)runtimeType1)) { throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_InvalidRequestedType"), (object)requestedType.ToString())); } this.TypeInfo = !runtimeType1.IsCOMObject ? (IRemotingTypeInfo)InternalRemotingServices.GetReflectionCachedData(runtimeType2).TypeInfo : (IRemotingTypeInfo) new DynamicTypeInfo(runtimeType2); if (!idObj.IsWellKnown()) { this.EnvoyInfo = System.Runtime.Remoting.EnvoyInfo.CreateEnvoyInfo(idObj as ServerIdentity); IChannelInfo channelInfo = (IChannelInfo) new System.Runtime.Remoting.ChannelInfo(); if (o is AppDomain) { object[] channelData = channelInfo.ChannelData; int length1 = channelData.Length; object[] objArray1 = new object[length1]; object[] objArray2 = objArray1; int length2 = length1; Array.Copy((Array)channelData, (Array)objArray2, length2); for (int index = 0; index < length1; ++index) { if (!(objArray1[index] is CrossAppDomainData)) { objArray1[index] = (object)null; } } channelInfo.ChannelData = objArray1; } this.ChannelInfo = channelInfo; if (runtimeType1.HasProxyAttribute) { this.SetHasProxyAttribute(); } } else { this.SetWellKnown(); } if (!ObjRef.ShouldUseUrlObjRef()) { return; } if (this.IsWellKnown()) { this.SetObjRefLite(); } else { string httpUrlForObject = ChannelServices.FindFirstHttpUrlForObject(this.URI); if (httpUrlForObject == null) { return; } this.URI = httpUrlForObject; this.SetObjRefLite(); } }