///<summary> /// checks, whether <paramref name="target"/> supports the methods of <paramref name="requiredType"/>. /// Supports testing transparent proxies. ///</summary> ///<param name="target">the target instance or <c>null</c></param> ///<param name="targetName">the name of the target to be used in error messages</param> ///<param name="requiredType">the type to test for</param> /// <exception cref="ArgumentNullException"> /// if <paramref name="requiredType"/> is <c>null</c> /// </exception> /// <exception cref="NotSupportedException"> /// if it is not possible to invoke methods of /// type <paramref name="requiredType"/> on <paramref name="target"/> /// </exception> public static void Understands(object target, string targetName, Type requiredType) { ArgumentNotNull(requiredType, "requiredType"); if (target == null) { throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Target '{0}' is null.", targetName)); } Type targetType; if (RemotingServices.IsTransparentProxy(target)) { RealProxy rp = RemotingServices.GetRealProxy(target); IRemotingTypeInfo rti = rp as IRemotingTypeInfo; if (rti != null) { if (rti.CanCastTo(requiredType, target)) { return; } throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Target '{0}' is a transparent proxy that does not support methods of '{1}'.", targetName, requiredType.FullName)); } targetType = rp.GetProxiedType(); } else { targetType = target.GetType(); } if (!requiredType.IsAssignableFrom(targetType)) { throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Target '{0}' of type '{1}' does not support methods of '{2}'.", targetName, targetType, requiredType.FullName)); } }
public ObjRef(MarshalByRefObject o, Type requestedType) { if (o == null) { throw new ArgumentNullException("o"); } if (requestedType == null) { throw new ArgumentNullException("requestedType"); } // The ObjRef can only be constructed if the given o // has already been marshalled using RemotingServices.Marshall uri = RemotingServices.GetObjectUri(o); typeInfo = new TypeInfo(requestedType); if (!requestedType.IsInstanceOfType(o)) { throw new RemotingException("The server object type cannot be cast to the requested type " + requestedType.FullName); } UpdateChannelInfo(); }
protected ObjRef(SerializationInfo info, StreamingContext context) { SerializationInfoEnumerator en = info.GetEnumerator(); // Info to serialize: uri, objrefFlags, typeInfo, envoyInfo, channelInfo bool marshalledValue = true; while (en.MoveNext()) { switch (en.Name) { case "uri": uri = (string)en.Value; break; case "typeInfo": typeInfo = (IRemotingTypeInfo)en.Value; break; case "channelInfo": channel_info = (IChannelInfo)en.Value; break; case "envoyInfo": envoyInfo = (IEnvoyInfo)en.Value; break; case "fIsMarshalled": int status; Object o = en.Value; if (o is string) { status = ((IConvertible)o).ToInt32(null); } else { status = (int)o; } if (status == 0) { marshalledValue = false; } break; case "objrefFlags": flags = Convert.ToInt32(en.Value); break; default: throw new NotSupportedException(); } } if (marshalledValue) { flags |= MarshalledObjectRef; } }
protected ObjRef(SerializationInfo info, StreamingContext context) { string str = (string)null; bool flag = false; SerializationInfoEnumerator enumerator = info.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Name.Equals("uri")) { this.uri = (string)enumerator.Value; } else if (enumerator.Name.Equals("typeInfo")) { this.typeInfo = (IRemotingTypeInfo)enumerator.Value; } else if (enumerator.Name.Equals("envoyInfo")) { this.envoyInfo = (IEnvoyInfo)enumerator.Value; } else if (enumerator.Name.Equals("channelInfo")) { this.channelInfo = (IChannelInfo)enumerator.Value; } else if (enumerator.Name.Equals("objrefFlags")) { object obj = enumerator.Value; this.objrefFlags = !(obj.GetType() == typeof(string)) ? (int)obj : ((IConvertible)obj).ToInt32((IFormatProvider)null); } else if (enumerator.Name.Equals("fIsMarshalled")) { object obj = enumerator.Value; if ((!(obj.GetType() == typeof(string)) ? (int)obj : ((IConvertible)obj).ToInt32((IFormatProvider)null)) == 0) { flag = true; } } else if (enumerator.Name.Equals("url")) { str = (string)enumerator.Value; } else if (enumerator.Name.Equals("SrvIdentity")) { this.SetServerIdentity((GCHandle)enumerator.Value); } else if (enumerator.Name.Equals("DomainId")) { this.SetDomainID((int)enumerator.Value); } } this.objrefFlags = flag ? this.objrefFlags & -2 : this.objrefFlags | 1; if (str == null) { return; } this.uri = str; this.objrefFlags = this.objrefFlags | 4; }
internal ObjRef (ObjRef o, bool unmarshalAsProxy) { channel_info = o.channel_info; uri = o.uri; typeInfo = o.typeInfo; envoyInfo = o.envoyInfo; flags = o.flags; if (unmarshalAsProxy) flags |= MarshalledObjectRef; }
/// <summary>Initializes a new instance of the <see cref="T:System.Runtime.Remoting.ObjRef" /> class from serialized data.</summary> /// <param name="info">The object that holds the serialized object data. </param> /// <param name="context">The contextual information about the source or destination of the exception. </param> protected ObjRef(SerializationInfo info, StreamingContext context) { SerializationInfoEnumerator enumerator = info.GetEnumerator(); bool flag = true; while (enumerator.MoveNext()) { string name = enumerator.Name; switch (name) { case "uri": this.uri = (string)enumerator.Value; continue; case "typeInfo": this.typeInfo = (IRemotingTypeInfo)enumerator.Value; continue; case "channelInfo": this.channel_info = (IChannelInfo)enumerator.Value; continue; case "envoyInfo": this.envoyInfo = (IEnvoyInfo)enumerator.Value; continue; case "fIsMarshalled": { object value = enumerator.Value; int num2; if (value is string) { num2 = ((IConvertible)value).ToInt32(null); } else { num2 = (int)value; } if (num2 == 0) { flag = false; } continue; } case "objrefFlags": this.flags = Convert.ToInt32(enumerator.Value); continue; } throw new NotSupportedException(); } if (flag) { this.flags |= ObjRef.MarshalledObjectRef; } }
private ObjRef(ObjRef o) { this.uri = o.uri; this.typeInfo = o.typeInfo; this.envoyInfo = o.envoyInfo; this.channelInfo = o.channelInfo; this.objrefFlags = o.objrefFlags; this.SetServerIdentity(o.GetServerIdentity()); this.SetDomainID(o.GetDomainID()); }
internal ObjRef DeserializeInTheCurrentDomain(int domainId, byte[] tInfo) { string local_uri = string.Copy(this.uri); ChannelInfo cinfo = new ChannelInfo(new CrossAppDomainData(domainId)); ObjRef res = new ObjRef(local_uri, cinfo); IRemotingTypeInfo typeInfo = (IRemotingTypeInfo)CADSerializer.DeserializeObjectSafe(tInfo); res.typeInfo = typeInfo; return(res); }
// shallow copy constructor used for smuggling. private ObjRef(ObjRef o) { BCLDebug.Assert(o.GetType() == typeof(ObjRef), "this should be just an ObjRef"); uri = o.uri; typeInfo = o.typeInfo; envoyInfo = o.envoyInfo; channelInfo = o.channelInfo; objrefFlags = o.objrefFlags; } // ObjRef
internal ObjRef(Type type, string url, object remoteChannelData) { this.uri = url; this.typeInfo = new TypeInfo(type); if (remoteChannelData != null) { this.channel_info = new ChannelInfo(remoteChannelData); } this.flags |= ObjRef.WellKnowObjectRef; }
internal ObjRef(Type type, string url, object remoteChannelData) { uri = url; typeInfo = new TypeInfo(type); if (remoteChannelData != null) { channel_info = new ChannelInfo(remoteChannelData); } flags |= WellKnowObjectRef; }
// shallow copy constructor used for smuggling. private ObjRef(ObjRef o) { BCLDebug.Assert(o.GetType() == typeof(ObjRef), "this should be just an ObjRef"); uri = o.uri; typeInfo = o.typeInfo; envoyInfo = o.envoyInfo; channelInfo = o.channelInfo; objrefFlags = o.objrefFlags; SetServerIdentity(o.GetServerIdentity()); SetDomainID(o.GetDomainID()); } // ObjRef
internal ObjRef(ObjRef o, bool unmarshalAsProxy) { this.channel_info = o.channel_info; this.uri = o.uri; this.typeInfo = o.typeInfo; this.envoyInfo = o.envoyInfo; this.flags = o.flags; if (unmarshalAsProxy) { this.flags |= ObjRef.MarshalledObjectRef; } }
// Check whether we can cast the transparent proxy to the given type public bool CanCastTo(Type castType, Object o) { bool fCastOK = false; // The identity should be non-null BCLDebug.Assert(null != IdentityObject, "null != IdentityObject"); Message.DebugOut("CheckCast for identity " + IdentityObject.GetType()); if ((castType == s_typeofObject) || (castType == s_typeofMarshalByRefObject)) { return(true); } // Get the objref of the proxy ObjRef oRef = IdentityObject.ObjectRef; // If the object ref is non-null then check against the type info // stored in the it if (null != oRef) { Object oTP = GetTransparentProxy(); // Check that there is a matching type in the server object // hierarchy represented in the objref Message.DebugOut("Calling CanCastTo for type " + castType); IRemotingTypeInfo typeInfo = oRef.TypeInfo; if (null != typeInfo) { fCastOK = typeInfo.CanCastTo(castType, oTP); if (!fCastOK && typeInfo.GetType() == typeof(TypeInfo) && oRef.IsWellKnown()) { fCastOK = CanCastToWK(castType); } } else { if (oRef.IsObjRefLite()) { // we should do a dynamic cast across the network fCastOK = MarshalByRefObject.CanCastToXmlTypeHelper(castType, (MarshalByRefObject)o); } } } // This is a well known object which does not have a backing ObjRef else { fCastOK = CanCastToWK(castType); } return(fCastOK); }
internal ObjRef(ObjRef o, bool unmarshalAsProxy) { channel_info = o.channel_info; uri = o.uri; typeInfo = o.typeInfo; envoyInfo = o.envoyInfo; flags = o.flags; if (unmarshalAsProxy) { flags |= MarshalledObjectRef; } }
internal ObjRef(Type type, string url, object remoteChannelData) { uri = url; typeInfo = new TypeInfo(type); #if !DISABLE_REMOTING if (remoteChannelData != null) { channel_info = new ChannelInfo(remoteChannelData); } #endif flags |= WellKnowObjectRef; }
/// <summary>Initializes a new instance of the <see cref="T:System.Runtime.Remoting.ObjRef" /> class to reference a specified <see cref="T:System.MarshalByRefObject" /> of a specified <see cref="T:System.Type" />.</summary> /// <param name="o">The object that the new <see cref="T:System.Runtime.Remoting.ObjRef" /> instance will reference. </param> /// <param name="requestedType">The <see cref="T:System.Type" /> of the object that the new <see cref="T:System.Runtime.Remoting.ObjRef" /> instance will reference. </param> public ObjRef(MarshalByRefObject o, Type requestedType) { if (o == null) { throw new ArgumentNullException("o"); } if (requestedType == null) { throw new ArgumentNullException("requestedType"); } this.uri = RemotingServices.GetObjectUri(o); this.typeInfo = new TypeInfo(requestedType); if (!requestedType.IsInstanceOfType(o)) { throw new RemotingException("The server object type cannot be cast to the requested type " + requestedType.FullName); } this.UpdateChannelInfo(); }
public override IMessage Invoke(IMessage message) { RealProxy delegatingProxy = null; IMethodCallMessage msg = message as IMethodCallMessage; try { delegatingProxy = serviceChannelCreator.CreateChannel(); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } return(new ReturnMessage(DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(e.GetBaseException().Message, Marshal.GetHRForException(e.GetBaseException()))), msg)); } MethodBase typeMethod = msg.MethodBase; IRemotingTypeInfo typeInfo = delegatingProxy as IRemotingTypeInfo; if (typeInfo == null) { throw Fx.AssertAndThrow("Type Info cannot be null"); } if (typeInfo.CanCastTo(typeMethod.DeclaringType, null)) { IMessage msgReturned = delegatingProxy.Invoke(message); ReturnMessage returnMsg = msgReturned as ReturnMessage; if ((returnMsg == null) || (returnMsg.Exception == null)) { return(msgReturned); } else { return(new ReturnMessage(DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(returnMsg.Exception.GetBaseException().Message, Marshal.GetHRForException(returnMsg.Exception.GetBaseException()))), msg)); } } else { return(new ReturnMessage(DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(SR.GetString(SR.OperationNotFound, typeMethod.Name), HR.DISP_E_UNKNOWNNAME)), msg)); } }
public bool CanCastTo(Type castType, object o) { if (castType == (Type)null) { throw new ArgumentNullException("castType"); } RuntimeType castType1 = castType as RuntimeType; if (castType1 == (RuntimeType)null) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); } bool flag = false; if (castType1 == RemotingProxy.s_typeofObject || castType1 == RemotingProxy.s_typeofMarshalByRefObject) { return(true); } ObjRef objectRef = this.IdentityObject.ObjectRef; if (objectRef != null) { object transparentProxy = this.GetTransparentProxy(); IRemotingTypeInfo typeInfo = objectRef.TypeInfo; if (typeInfo != null) { flag = typeInfo.CanCastTo((Type)castType1, transparentProxy); if (!flag && typeInfo.GetType() == typeof(System.Runtime.Remoting.TypeInfo) && objectRef.IsWellKnown()) { flag = this.CanCastToWK((Type)castType1); } } else if (objectRef.IsObjRefLite()) { flag = MarshalByRefObject.CanCastToXmlTypeHelper(castType1, (MarshalByRefObject)o); } } else { flag = this.CanCastToWK((Type)castType1); } return(flag); }
public static void Main() { ChannelServices.RegisterChannel(new HttpChannel(0)); RemotingConfiguration.RegisterActivatedClientType(typeof(SampleService), "http://localhost:9000/MySampleService"); SampleService myRemoteObject = new SampleService(); bool result = myRemoteObject.SampleMethod(); // System.Runtime.Remoting.RemotingServices.GetObjRefForProxy // <Snippet1> ObjRef objRefSample = RemotingServices.GetObjRefForProxy(myRemoteObject); Console.WriteLine("***ObjRef Details***"); Console.WriteLine("URI:\t{0}", objRefSample.URI); object[] channelData = objRefSample.ChannelInfo.ChannelData; Console.WriteLine("Channel Info:"); foreach (object o in channelData) { Console.WriteLine("\t{0}", o.ToString()); } IEnvoyInfo envoyInfo = objRefSample.EnvoyInfo; if (envoyInfo == null) { Console.WriteLine("This ObjRef does not have envoy information."); } else { IMessageSink envoySinks = envoyInfo.EnvoySinks; Console.WriteLine("Envoy Sink Class: {0}", envoySinks); } IRemotingTypeInfo typeInfo = objRefSample.TypeInfo; Console.WriteLine("Remote type name: {0}", typeInfo.TypeName); Console.WriteLine("Can my object cast to a Bitmap? {0}", typeInfo.CanCastTo(typeof(System.Drawing.Bitmap), objRefSample)); // </Snippet1> }
public bool CanCastTo(Type castType, object o) { if (castType == null) { throw new ArgumentNullException("castType"); } RuntimeType fromType = castType as RuntimeType; if (fromType == null) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); } bool flag = false; if ((fromType == s_typeofObject) || (fromType == s_typeofMarshalByRefObject)) { return(true); } ObjRef objectRef = this.IdentityObject.ObjectRef; if (objectRef != null) { object transparentProxy = this.GetTransparentProxy(); IRemotingTypeInfo typeInfo = objectRef.TypeInfo; if (typeInfo != null) { flag = typeInfo.CanCastTo(fromType, transparentProxy); if ((!flag && (typeInfo.GetType() == typeof(TypeInfo))) && objectRef.IsWellKnown()) { flag = this.CanCastToWK(fromType); } return(flag); } if (objectRef.IsObjRefLite()) { flag = MarshalByRefObject.CanCastToXmlTypeHelper(fromType, (MarshalByRefObject)o); } return(flag); } return(this.CanCastToWK(fromType)); }
/// <summary>Returns the transparent proxy for the current instance of <see cref="T:System.Runtime.Remoting.Proxies.RealProxy" />.</summary> /// <returns>The transparent proxy for the current proxy instance.</returns> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Infrastructure" /> /// </PermissionSet> public virtual object GetTransparentProxy() { if (this._objTP == null) { IRemotingTypeInfo remotingTypeInfo = this as IRemotingTypeInfo; string text; if (remotingTypeInfo != null) { text = remotingTypeInfo.TypeName; if (text == null || text == typeof(MarshalByRefObject).AssemblyQualifiedName) { text = this.class_to_proxy.AssemblyQualifiedName; } } else { text = this.class_to_proxy.AssemblyQualifiedName; } this._objTP = this.InternalGetTransparentProxy(text); } return(this._objTP); }
///<summary> /// checks, whether <paramref name="target"/> supports the methods of <paramref name="requiredType"/>. /// Supports testing transparent proxies. ///</summary> ///<param name="target">the target instance or <c>null</c></param> ///<param name="targetName">the name of the target to be used in error messages</param> ///<param name="requiredType">the type to test for</param> /// <exception cref="ArgumentNullException"> /// if <paramref name="requiredType"/> is <c>null</c> /// </exception> /// <exception cref="NotSupportedException"> /// if it is not possible to invoke methods of /// type <paramref name="requiredType"/> on <paramref name="target"/> /// </exception> public static void Understands(object target, string targetName, Type requiredType) { ArgumentNotNull(requiredType, "requiredType"); if (target == null) { ThrowNotSupportedException($"Target '{targetName}' is null."); } Type targetType = null; if (RemotingServices.IsTransparentProxy(target)) { #if !NETSTANDARD System.Runtime.Remoting.Proxies.RealProxy rp = RemotingServices.GetRealProxy(target); IRemotingTypeInfo rti = rp as IRemotingTypeInfo; if (rti != null) { if (rti.CanCastTo(requiredType, target)) { return; } ThrowNotSupportedException( $"Target '{targetName}' is a transparent proxy that does not support methods of '{requiredType.FullName}'."); } targetType = rp.GetProxiedType(); #endif } else { targetType = target.GetType(); } if (!requiredType.IsAssignableFrom(targetType)) { ThrowNotSupportedException($"Target '{targetName}' of type '{targetType}' does not support methods of '{requiredType.FullName}'."); } }
public virtual object GetTransparentProxy() { if (_objTP == null) { string name; IRemotingTypeInfo rti = this as IRemotingTypeInfo; if (rti != null) { name = rti.TypeName; if (name == null || name == typeof(MarshalByRefObject).AssemblyQualifiedName) { name = class_to_proxy.AssemblyQualifiedName; } } else { name = class_to_proxy.AssemblyQualifiedName; } _objTP = InternalGetTransparentProxy(name); } return(_objTP); }
public override IMessage Invoke(IMessage message) { RealProxy proxy = null; IMethodCallMessage mcm = message as IMethodCallMessage; try { proxy = this.serviceChannelCreator.CreateChannel(); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } return(new ReturnMessage(DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(exception.GetBaseException().Message, Marshal.GetHRForException(exception.GetBaseException()))), mcm)); } MethodBase methodBase = mcm.MethodBase; IRemotingTypeInfo info = proxy as IRemotingTypeInfo; if (info == null) { throw Fx.AssertAndThrow("Type Info cannot be null"); } if (info.CanCastTo(methodBase.DeclaringType, null)) { IMessage message3 = proxy.Invoke(message); ReturnMessage message4 = message3 as ReturnMessage; if ((message4 != null) && (message4.Exception != null)) { return(new ReturnMessage(DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(message4.Exception.GetBaseException().Message, Marshal.GetHRForException(message4.Exception.GetBaseException()))), mcm)); } return(message3); } return(new ReturnMessage(DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(System.ServiceModel.SR.GetString("OperationNotFound", new object[] { methodBase.Name }), HR.DISP_E_UNKNOWNNAME)), mcm)); }
protected ObjRef(SerializationInfo info, StreamingContext context) { string str = null; bool flag = false; SerializationInfoEnumerator enumerator = info.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Name.Equals("uri")) { this.uri = (string) enumerator.Value; } else { if (enumerator.Name.Equals("typeInfo")) { this.typeInfo = (IRemotingTypeInfo) enumerator.Value; continue; } if (enumerator.Name.Equals("envoyInfo")) { this.envoyInfo = (IEnvoyInfo) enumerator.Value; continue; } if (enumerator.Name.Equals("channelInfo")) { this.channelInfo = (IChannelInfo) enumerator.Value; continue; } if (enumerator.Name.Equals("objrefFlags")) { object obj2 = enumerator.Value; if (obj2.GetType() == typeof(string)) { this.objrefFlags = ((IConvertible) obj2).ToInt32(null); } else { this.objrefFlags = (int) obj2; } continue; } if (enumerator.Name.Equals("fIsMarshalled")) { int num; object obj3 = enumerator.Value; if (obj3.GetType() == typeof(string)) { num = ((IConvertible) obj3).ToInt32(null); } else { num = (int) obj3; } if (num == 0) { flag = true; } continue; } if (enumerator.Name.Equals("url")) { str = (string) enumerator.Value; } else { if (enumerator.Name.Equals("SrvIdentity")) { this.SetServerIdentity((GCHandle) enumerator.Value); continue; } if (enumerator.Name.Equals("DomainId")) { this.SetDomainID((int) enumerator.Value); } } } } if (!flag) { this.objrefFlags |= 1; } else { this.objrefFlags &= -2; } if (str != null) { this.uri = str; this.objrefFlags |= 4; } }
/// <include file='doc\ObjRef.uex' path='docs/doc[@for="ObjRef.ObjRef2"]/*' /> protected ObjRef(SerializationInfo info, StreamingContext context) { String url = null; // an objref lite url bool bFoundFIsMarshalled = false; SerializationInfoEnumerator e = info.GetEnumerator(); while (e.MoveNext()) { if (e.Name.Equals("uri")) { uri = (String) e.Value; } else if (e.Name.Equals("typeInfo")) { typeInfo = (IRemotingTypeInfo) e.Value; } else if (e.Name.Equals("envoyInfo")) { envoyInfo = (IEnvoyInfo) e.Value; } else if (e.Name.Equals("channelInfo")) { channelInfo = (IChannelInfo) e.Value; } else if (e.Name.Equals("objrefFlags")) { Object o = e.Value; if(o.GetType() == typeof(String)) { objrefFlags = ((IConvertible)o).ToInt32(null); } else { objrefFlags = (int)o; } } else if (e.Name.Equals("fIsMarshalled")) { int value; Object o = e.Value; if(o.GetType() == typeof(String)) value = ((IConvertible)o).ToInt32(null); else value = (int)o; if (value == 0) bFoundFIsMarshalled = true; } else if (e.Name.Equals("url")) { url = (String)e.Value; } } if (!bFoundFIsMarshalled) { // This ObjRef was not passed as a parameter, so we need to unmarshal it. objrefFlags |= FLG_MARSHALED_OBJECT; } // If only url is present, then it is an ObjRefLite. if (url != null) { uri = url; objrefFlags |= FLG_LITE_OBJREF; } } // ObjRef .ctor
public ObjRef (MarshalByRefObject o, Type requestedType) { if (o == null) throw new ArgumentNullException ("o"); if (requestedType == null) throw new ArgumentNullException ("requestedType"); // The ObjRef can only be constructed if the given o // has already been marshalled using RemotingServices.Marshall uri = RemotingServices.GetObjectUri (o); typeInfo = new TypeInfo (requestedType); if (!requestedType.IsInstanceOfType (o)) throw new RemotingException ("The server object type cannot be cast to the requested type " + requestedType.FullName); UpdateChannelInfo(); }
protected ObjRef(SerializationInfo info, StreamingContext context) { String url = null; // an objref lite url bool bFoundFIsMarshalled = false; SerializationInfoEnumerator e = info.GetEnumerator(); while (e.MoveNext()) { if (e.Name.Equals("uri")) { uri = (String)e.Value; } else if (e.Name.Equals("typeInfo")) { typeInfo = (IRemotingTypeInfo)e.Value; } else if (e.Name.Equals("envoyInfo")) { envoyInfo = (IEnvoyInfo)e.Value; } else if (e.Name.Equals("channelInfo")) { channelInfo = (IChannelInfo)e.Value; } else if (e.Name.Equals("objrefFlags")) { Object o = e.Value; if (o.GetType() == typeof(String)) { objrefFlags = ((IConvertible)o).ToInt32(null); } else { objrefFlags = (int)o; } } else if (e.Name.Equals("fIsMarshalled")) { int value; Object o = e.Value; if (o.GetType() == typeof(String)) { value = ((IConvertible)o).ToInt32(null); } else { value = (int)o; } if (value == 0) { bFoundFIsMarshalled = true; } } else if (e.Name.Equals("url")) { url = (String)e.Value; } else if (e.Name.Equals("SrvIdentity")) { SetServerIdentity((GCHandle)e.Value); } else if (e.Name.Equals("DomainId")) { SetDomainID((int)e.Value); } } if (!bFoundFIsMarshalled) { // This ObjRef was not passed as a parameter, so we need to unmarshal it. objrefFlags |= FLG_MARSHALED_OBJECT; } else { objrefFlags &= ~FLG_MARSHALED_OBJECT; } // If only url is present, then it is an ObjRefLite. if (url != null) { uri = url; objrefFlags |= FLG_LITE_OBJREF; } } // ObjRef .ctor
internal ObjRef(string typeName, string uri, IChannelInfo cinfo) { this.uri = uri; channel_info = cinfo; typeInfo = new TypeInfo(Type.GetType(typeName, true)); }
internal ObjRef (string typeName, string uri, IChannelInfo cinfo) { this.uri = uri; channel_info = cinfo; typeInfo = new TypeInfo (Type.GetType (typeName, true)); }
protected ObjRef(SerializationInfo info, StreamingContext context) { string str = null; bool flag = false; SerializationInfoEnumerator enumerator = info.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Name.Equals("uri")) { this.uri = (string)enumerator.Value; } else { if (enumerator.Name.Equals("typeInfo")) { this.typeInfo = (IRemotingTypeInfo)enumerator.Value; continue; } if (enumerator.Name.Equals("envoyInfo")) { this.envoyInfo = (IEnvoyInfo)enumerator.Value; continue; } if (enumerator.Name.Equals("channelInfo")) { this.channelInfo = (IChannelInfo)enumerator.Value; continue; } if (enumerator.Name.Equals("objrefFlags")) { object obj2 = enumerator.Value; if (obj2.GetType() == typeof(string)) { this.objrefFlags = ((IConvertible)obj2).ToInt32(null); } else { this.objrefFlags = (int)obj2; } continue; } if (enumerator.Name.Equals("fIsMarshalled")) { int num; object obj3 = enumerator.Value; if (obj3.GetType() == typeof(string)) { num = ((IConvertible)obj3).ToInt32(null); } else { num = (int)obj3; } if (num == 0) { flag = true; } continue; } if (enumerator.Name.Equals("url")) { str = (string)enumerator.Value; } else { if (enumerator.Name.Equals("SrvIdentity")) { this.SetServerIdentity((GCHandle)enumerator.Value); continue; } if (enumerator.Name.Equals("DomainId")) { this.SetDomainID((int)enumerator.Value); } } } } if (!flag) { this.objrefFlags |= 1; } else { this.objrefFlags &= -2; } if (str != null) { this.uri = str; this.objrefFlags |= 4; } }
internal ObjRef (Type type, string url, object remoteChannelData) { uri = url; typeInfo = new TypeInfo(type); if (remoteChannelData != null) channel_info = new ChannelInfo (remoteChannelData); flags |= WellKnowObjectRef; }
protected ObjRef (SerializationInfo info, StreamingContext context) { SerializationInfoEnumerator en = info.GetEnumerator(); // Info to serialize: uri, objrefFlags, typeInfo, envoyInfo, channelInfo bool marshalledValue = true; while (en.MoveNext ()) { switch (en.Name) { case "uri": uri = (string)en.Value; break; case "typeInfo": typeInfo = (IRemotingTypeInfo)en.Value; break; case "channelInfo": channel_info = (IChannelInfo)en.Value; break; case "envoyInfo": envoyInfo = (IEnvoyInfo)en.Value; break; case "fIsMarshalled": int status; Object o = en.Value; if (o is string) status = ((IConvertible) o).ToInt32(null); else status = (int) o; if (status == 0) marshalledValue = false; break; case "objrefFlags": flags = Convert.ToInt32 (en.Value); break; default: throw new NotSupportedException (); } } if (marshalledValue) flags |= MarshalledObjectRef; }
[System.Security.SecurityCritical] // auto-generated private ObjRef(ObjRef o) { BCLDebug.Assert(o.GetType() == typeof(ObjRef), "this should be just an ObjRef"); uri = o.uri; typeInfo = o.typeInfo; envoyInfo = o.envoyInfo; channelInfo = o.channelInfo; objrefFlags = o.objrefFlags; SetServerIdentity(o.GetServerIdentity()); SetDomainID(o.GetDomainID()); } // ObjRef
// Check whether we can cast the transparent proxy to the given type public bool CanCastTo(Type castType, Object o) { bool fCastOK = false; // The identity should be non-null BCLDebug.Assert(null != IdentityObject, "null != IdentityObject"); Message.DebugOut("CheckCast for identity " + IdentityObject.GetType()); if ((castType == s_typeofObject) || (castType == s_typeofMarshalByRefObject)) { return(true); } // Get the objref of the proxy ObjRef oRef = IdentityObject.ObjectRef; // If the object ref is non-null then check against the type info // stored in the it if (null != oRef) { Object oTP = GetTransparentProxy(); // Check that there is a matching type in the server object // hierarchy represented in the objref Message.DebugOut("Calling CanCastTo for type " + castType); IRemotingTypeInfo typeInfo = oRef.TypeInfo; if (null != typeInfo) { fCastOK = typeInfo.CanCastTo(castType, oTP); } else { if (oRef.IsObjRefLite()) { // we should do a dynamic cast across the network fCastOK = MarshalByRefObject.CanCastToXmlTypeHelper(castType, (MarshalByRefObject)o); } } } // This is a well known object which does not have a backing ObjRef else { Message.DebugOut("CheckCast for well known objects and type " + castType); // Check whether the type to which we want to cast is // compatible with the current type if (castType.IsClass) { fCastOK = GetProxiedType().IsAssignableFrom(castType); } else { // NOTE: we are coming here also for x-context proxies // when unmanaged code cannot determine if the cast is not // okay if (!(IdentityObject is ServerIdentity)) { BCLDebug.Assert( IdentityObject.URI != null, "Bad WellKnown ID"); // Always allow interface casts to succeed. If the // interface is not supported by the well known object // then we will throw an exception when the interface // is invoked. fCastOK = true; } } } return(fCastOK); }