public override IMessage Invoke(IMessage msg) { if (msg is IConstructionCallMessage) { IConstructionCallMessage constructCallMsg = msg as IConstructionCallMessage; IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg); RealProxy.SetStubData(this, constructionReturnMessage.ReturnValue); Console.WriteLine("Call constructor"); return(constructionReturnMessage); } else { IMethodCallMessage callMsg = msg as IMethodCallMessage; IMessage message; try { Console.WriteLine(callMsg.MethodName + "执行前。。。"); object[] args = callMsg.Args; object o = callMsg.MethodBase.Invoke(GetUnwrappedServer(), args); Console.WriteLine(callMsg.MethodName + "执行后。。。"); message = new ReturnMessage(o, args, args.Length, callMsg.LogicalCallContext, callMsg); } catch (Exception e) { message = new ReturnMessage(e, callMsg); } Console.WriteLine(message.Properties["__Return"]); return(message); } }
public override IMessage Invoke(IMessage message) { if (message is IConstructionCallMessage) { IConstructionReturnMessage myIConstructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)message); ConstructionResponse constructionResponse = new ConstructionResponse(null, (IMethodCallMessage)message); return(constructionResponse); } IMethodCallMessage methodMessage = new MethodCallMessageWrapper((IMethodCallMessage)message); MethodBase method = methodMessage.MethodBase; object returnValue = null; if (method.DeclaringType == typeof(IDynamicProxy)) { returnValue = method.Invoke(this, methodMessage.Args); } else { returnValue = InvocationHandler(ProxyTargetTyped, method, methodMessage.Args); } ReturnMessage returnMessage = new ReturnMessage(returnValue, methodMessage.Args, methodMessage.ArgCount, methodMessage.LogicalCallContext, methodMessage); return(returnMessage); }
private ChoRealProxyInstanceState GetInstance(IConstructionCallMessage ctorCallMessage) { if (_instances.ContainsKey(ctorCallMessage.ActivationType)) { return(_instances[ctorCallMessage.ActivationType]); } lock (_padLock) { if (!_instances.ContainsKey(ctorCallMessage.ActivationType)) { IConstructionReturnMessage retMsg = InitializeServerObject(ctorCallMessage); IConstructionReturnMessage response = null; if (retMsg.Exception == null) { _target = GetUnwrappedServer(); SetStubData(this, _target); response = EnterpriseServicesHelper.CreateConstructionReturnMessage(ctorCallMessage, (MarshalByRefObject)this.GetTransparentProxy()); } _instances.Add(ctorCallMessage.ActivationType, new ChoRealProxyInstanceState() { Target = _target, MethodMessage = response, Exception = retMsg.Exception, IsInitialized = false }); } return(_instances[ctorCallMessage.ActivationType]); } }
public override IMessage Invoke(IMessage myMessage) { Console.WriteLine("MyProxy 'Invoke method' Called..."); if (myMessage is IMethodCallMessage) { Console.WriteLine("IMethodCallMessage"); } if (myMessage is IMethodReturnMessage) { Console.WriteLine("IMethodReturnMessage"); } if (myMessage is IConstructionCallMessage) { // Initialize a new instance of remote object IConstructionReturnMessage myIConstructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)myMessage); ConstructionResponse constructionResponse = new ConstructionResponse(null, (IMethodCallMessage)myMessage); return(constructionResponse); } IDictionary myIDictionary = myMessage.Properties; IMessage returnMessage; myIDictionary["__Uri"] = myUri; // Synchronously dispatch messages to server. returnMessage = ChannelServices.SyncDispatchMessage(myMessage); // Pushing return value and OUT parameters back onto stack. IMethodReturnMessage myMethodReturnMessage = (IMethodReturnMessage)returnMessage; return(returnMessage); }
internal static IConstructionReturnMessage Activate(RemotingProxy remProxy, IConstructionCallMessage ctorMsg) { IConstructionReturnMessage message = null; if (((ConstructorCallMessage)ctorMsg).ActivateInContext) { message = ctorMsg.Activator.Activate(ctorMsg); if (message.Exception != null) { throw message.Exception; } return(message); } GetPropertiesFromAttributes(ctorMsg, ctorMsg.CallSiteActivationAttributes); GetPropertiesFromAttributes(ctorMsg, ((ConstructorCallMessage)ctorMsg).GetWOMAttributes()); GetPropertiesFromAttributes(ctorMsg, ((ConstructorCallMessage)ctorMsg).GetTypeAttributes()); IMethodReturnMessage message2 = (IMethodReturnMessage)Thread.CurrentContext.GetClientContextChain().SyncProcessMessage(ctorMsg); message = message2 as IConstructionReturnMessage; if (message2 == null) { throw new RemotingException(Environment.GetResourceString("Remoting_Activation_Failed")); } if (message2.Exception != null) { throw message2.Exception; } return(message); }
// Messages will be intercepted here and redirected // to another object. public override IMessage Invoke(IMessage msg) { if (msg is IConstructionCallMessage) { IActivator remActivator = (IActivator)RemotingServices.Connect(typeof(IActivator), "tcp://localhost:1234/RemoteActivationService.rem"); IConstructionReturnMessage crm = remActivator.Activate((IConstructionCallMessage)msg); return(crm); } else { methodOverloaded = RemotingServices.IsMethodOverloaded((IMethodMessage)msg); _mthBase = RemotingServices.GetMethodBaseFromMethodMessage((IMethodMessage)msg); MethodCallMessageWrapper mcm = new MethodCallMessageWrapper((IMethodCallMessage)msg); mcm.Uri = RemotingServices.GetObjectUri((MarshalByRefObject)target); MarshalByRefObject objRem = (MarshalByRefObject)Activator.CreateInstance(GetProxiedType()); RemotingServices.ExecuteMessage((MarshalByRefObject)objRem, (IMethodCallMessage)msg); IMessage rtnMsg = null; try { rtnMsg = _sink.SyncProcessMessage(msg); } catch (Exception e) { Console.WriteLine(e.Message); } return(rtnMsg); } }
private IConstructionReturnMessage InternalActivate(IConstructionCallMessage ctorMsg) { this.CtorThread = Thread.CurrentThread.GetHashCode(); IConstructionReturnMessage constructionReturnMessage = ActivationServices.Activate(this, ctorMsg); this.Initialized = true; return(constructionReturnMessage); }
/// <summary> /// 构造函数代理方法执行. /// </summary> /// <param name="methodInvoke">代理目标方法</param> /// <returns>代理结果</returns> public virtual IMessage ProcessConstruct(IMessage methodInvoke) { IConstructionCallMessage constructCallMsg = methodInvoke as IConstructionCallMessage; IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)methodInvoke); RealProxy.SetStubData(this, constructionReturnMessage.ReturnValue); return(constructionReturnMessage); }
public static IConstructionReturnMessage CreateConstructionReturnMessage(IConstructionCallMessage ctorMsg, MarshalByRefObject retObj) { IConstructionReturnMessage ctorRetMsg = null; // Create the return message ctorRetMsg = new ConstructorReturnMessage(retObj, null, 0, null, ctorMsg); // NOTE: WE ALLOW ONLY DEFAULT CTORs on SERVICEDCOMPONENTS return(ctorRetMsg); }
public void CollectFromServerContext(IConstructionReturnMessage msg) { var retProxy = msg.ReturnValue as ObjRef; try { _sink.SetCallable((IExternalCallable)RemotingServices.Unmarshal(retProxy, true)); } catch (InvalidCastException ex) { throw new InvalidOperationException("PInvokableContextAttribute may only be applied to to a class that implements IExternalCallable", ex); } }
internal void ConstructServer() { this.SetupContext(true); IConstructionReturnMessage message = base.InitializeServerObject(null); if ((message != null) && (message.Exception != null)) { ((ServicedComponent)this.GetTransparentProxy())._callFinalize(true); base.DetachServer(); throw message.Exception; } }
internal static IConstructionReturnMessage SetupConstructionReply(object serverObj, IConstructionCallMessage ctorMsg, Exception e) { IConstructionReturnMessage message = null; if (e == null) { return(new ConstructorReturnMessage((MarshalByRefObject)serverObj, null, 0, (LogicalCallContext)ctorMsg.Properties[Message.CallContextKey], ctorMsg)); } message = new ConstructorReturnMessage(e, null); ((ConstructorReturnMessage)message).SetLogicalCallContext((LogicalCallContext)ctorMsg.Properties[Message.CallContextKey]); return(message); }
internal static object DoCrossContextActivationCallback(object[] args) { IConstructionCallMessage constructionCallMessage = (IConstructionCallMessage)args[0]; IMethodReturnMessage methodReturnMessage = (IMethodReturnMessage)Thread.CurrentContext.GetServerContextChain().SyncProcessMessage((IMessage)constructionCallMessage); IConstructionReturnMessage constructionReturnMessage = methodReturnMessage as IConstructionReturnMessage; if (constructionReturnMessage == null) { constructionReturnMessage = (IConstructionReturnMessage) new ConstructorReturnMessage(methodReturnMessage == null ? (Exception) new RemotingException(Environment.GetResourceString("Remoting_Activation_Failed")) : methodReturnMessage.Exception, (IConstructionCallMessage)null); ((ReturnMessage)constructionReturnMessage).SetLogicalCallContext((LogicalCallContext)constructionCallMessage.Properties[(object)Message.CallContextKey]); } return((object)constructionReturnMessage); }
public virtual IMessage ProcessConstruct(IMessage msg) { IConstructionCallMessage constructCallMsg = msg as IConstructionCallMessage; //构造函数 初始化 IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg); RealProxy.SetStubData(this, constructionReturnMessage.ReturnValue); //Console.WriteLine("Call constructor:"+constructCallMsg.MethodName); //Console.WriteLine("Call constructor arg count:"+constructCallMsg.ArgCount); return(constructionReturnMessage); }
public IConstructionReturnMessage InitializeServerObject(IConstructionCallMessage ctorMsg) { IConstructionReturnMessage message = null; if (this._serverObject != null) { return(message); } Type proxiedType = this.GetProxiedType(); if ((ctorMsg != null) && (ctorMsg.ActivationType != proxiedType)) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Proxy_BadTypeForActivation"), new object[] { proxiedType.FullName, ctorMsg.ActivationType })); } this._serverObject = RemotingServices.AllocateUninitializedObject(proxiedType); this.SetContextForDefaultStub(); MarshalByRefObject transparentProxy = (MarshalByRefObject)this.GetTransparentProxy(); IMethodReturnMessage message2 = null; Exception e = null; if (ctorMsg != null) { message2 = RemotingServices.ExecuteMessage(transparentProxy, ctorMsg); e = message2.Exception; } else { try { RemotingServices.CallDefaultCtor(transparentProxy); } catch (Exception exception2) { e = exception2; } } if (e == null) { object[] outArgs = (message2 == null) ? null : message2.OutArgs; int outArgsCount = (outArgs == null) ? 0 : outArgs.Length; LogicalCallContext callCtx = (message2 == null) ? null : message2.LogicalCallContext; message = new ConstructorReturnMessage(transparentProxy, outArgs, outArgsCount, callCtx, ctorMsg); this.SetupIdentity(); if (this.IsRemotingProxy()) { ((RemotingProxy)this).Initialized = true; } return(message); } return(new ConstructorReturnMessage(e, ctorMsg)); }
public IConstructionReturnMessage InitializeServerObject(IConstructionCallMessage ctorMsg) { IConstructionReturnMessage result = null; if (this._serverObject == null) { Type proxiedType = this.GetProxiedType(); if (ctorMsg != null && ctorMsg.ActivationType != proxiedType) { throw new RemotingException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Proxy_BadTypeForActivation"), proxiedType.FullName, ctorMsg.ActivationType)); } this._serverObject = RemotingServices.AllocateUninitializedObject(proxiedType); this.SetContextForDefaultStub(); MarshalByRefObject marshalByRefObject = (MarshalByRefObject)this.GetTransparentProxy(); IMethodReturnMessage methodReturnMessage = null; Exception ex = null; if (ctorMsg != null) { methodReturnMessage = RemotingServices.ExecuteMessage(marshalByRefObject, ctorMsg); ex = methodReturnMessage.Exception; } else { try { RemotingServices.CallDefaultCtor(marshalByRefObject); } catch (Exception ex2) { ex = ex2; } } if (ex == null) { object[] array = (methodReturnMessage == null) ? null : methodReturnMessage.OutArgs; int outArgsCount = (array == null) ? 0 : array.Length; LogicalCallContext callCtx = (methodReturnMessage == null) ? null : methodReturnMessage.LogicalCallContext; result = new ConstructorReturnMessage(marshalByRefObject, array, outArgsCount, callCtx, ctorMsg); this.SetupIdentity(); if (this.IsRemotingProxy()) { ((RemotingProxy)this).Initialized = true; } } else { result = new ConstructorReturnMessage(ex, ctorMsg); } } return(result); }
public IConstructionReturnMessage InitializeServerObject(IConstructionCallMessage ctorMsg) { IConstructionReturnMessage constructionReturnMessage = (IConstructionReturnMessage)null; if (this._serverObject == null) { Type proxiedType = this.GetProxiedType(); if (ctorMsg != null && ctorMsg.ActivationType != proxiedType) { throw new RemotingException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Remoting_Proxy_BadTypeForActivation"), (object)proxiedType.FullName, (object)ctorMsg.ActivationType)); } this._serverObject = RemotingServices.AllocateUninitializedObject(proxiedType); this.SetContextForDefaultStub(); MarshalByRefObject marshalByRefObject = (MarshalByRefObject)this.GetTransparentProxy(); IMethodReturnMessage methodReturnMessage = (IMethodReturnMessage)null; Exception e = (Exception)null; if (ctorMsg != null) { methodReturnMessage = RemotingServices.ExecuteMessage(marshalByRefObject, (IMethodCallMessage)ctorMsg); e = methodReturnMessage.Exception; } else { try { RemotingServices.CallDefaultCtor((object)marshalByRefObject); } catch (Exception ex) { e = ex; } } if (e == null) { object[] outArgs = methodReturnMessage == null ? (object[])null : methodReturnMessage.OutArgs; int outArgsCount = outArgs == null ? 0 : outArgs.Length; LogicalCallContext callCtx = methodReturnMessage == null ? (LogicalCallContext)null : methodReturnMessage.LogicalCallContext; constructionReturnMessage = (IConstructionReturnMessage) new ConstructorReturnMessage(marshalByRefObject, outArgs, outArgsCount, callCtx, ctorMsg); this.SetupIdentity(); if (this.IsRemotingProxy()) { this.Initialized = true; } } else { constructionReturnMessage = (IConstructionReturnMessage) new ConstructorReturnMessage(e, ctorMsg); } } return(constructionReturnMessage); }
/// <include file='doc\remotingproxy.uex' path='docs/doc[@for="RemotingProxy.InternalActivate"]/*' /> // New method for activators. // This gets called during remoting intercepted activation when // JIT tries to run a constructor on a TP (which remoting gave it // in place of an actual uninitialized instance of the expected type) private IConstructionReturnMessage InternalActivate(IConstructionCallMessage ctorMsg) { // Remember the hashcode of the constructor thread. CtorThread = Thread.CurrentThread.GetHashCode(); IConstructionReturnMessage ctorRetMsg = ActivationServices.Activate(this, ctorMsg); // Set the flag to indicate that the object is initialized // Note: this assert is not valid for WKOs //BCLDebug.Assert(!Initialized, "Proxy marked as initialized before activation call completed"); Initialized = true; return(ctorRetMsg); }
//调用代理的类型的方法 public override IMessage Invoke(IMessage msg) { //用lock来防止多线程在一个时间同时操作方法 //lock (obj) //{ //} object returnIMessage = null; IMessage message; //如果是调用了构造函数就进入使用下面的代码 if (msg is IConstructionCallMessage) { //构造函数调用 IConstructionCallMessage constructCallMsg = msg as IConstructionCallMessage; IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg); RealProxy.SetStubData(this, constructionReturnMessage.ReturnValue); returnIMessage = constructionReturnMessage; } //如果调用方法是一般方法,进入If语句 else { var methodCall = msg as IMethodCallMessage; var methodInfo = methodCall.MethodBase as MethodInfo; //if(_Filter(methodInfo)) // Log("In Dynamic Proxy - Before executing '{0}'", methodCall.MethodName); OnBeforeExecute(methodCall); try { var result = methodInfo.Invoke(GetUnwrappedServer(), methodCall.InArgs); //if (_Filter(methodInfo)) // Log("In Dynamic Proxy - After executing '{0}' ", methodCall.MethodName); message = new ReturnMessage(result, null, 0, methodCall.LogicalCallContext, methodCall); OnAfterExecute(methodCall, message.Properties["__Return"]); returnIMessage = message; } catch (Exception ex) { // if (_Filter(methodInfo)) // Log(string.Format( //"In Dynamic Proxy- Exception {0} executing '{1}'", ex), //methodCall.MethodName); OnErrorExecuting(methodCall, ex.InnerException.ToString()); returnIMessage = new ReturnMessage(ex, methodCall); } } return(returnIMessage as IMessage); }
public override IMessage Invoke(IMessage msg) { Exception InnerException; msg.Properties["__Uri"] = _TcpUrl; IMessage retMsg = _messageSinks[0].SyncProcessMessage(msg); // Handle construction call message differently than other method // call messages. if (msg is IConstructionCallMessage) { // need to finish CAO activation manually. string url = GetUrlForCAO(_serverType); if (url.Length > 0) { ActivatedCAO((IConstructionCallMessage)msg, url); } IConstructionReturnMessage crm = EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)msg, (MarshalByRefObject)this.GetTransparentProxy()); return(crm); } else { if (retMsg is IMethodReturnMessage) { IMethodReturnMessage mrm = (IMethodReturnMessage)retMsg; if (mrm.Exception == null) { return(retMsg); } else { InnerException = mrm.Exception; } } else { MethodCallMessageWrapper mcm = new MethodCallMessageWrapper((IMethodCallMessage)msg); mcm.Uri = RemotingServices.GetObjectUri((MarshalByRefObject)_targetTcp); return(RemotingServices.GetEnvoyChainForProxy((MarshalByRefObject)_targetTcp).SyncProcessMessage(msg)); } msg.Properties["__Uri"] = _HttpUrl; retMsg = _messageSinks[1].SyncProcessMessage(msg); if (retMsg is IMethodReturnMessage) { IMethodReturnMessage mrm = (IMethodReturnMessage)retMsg; } return(retMsg); } }
private void ActivatedCAO(IConstructionCallMessage ccm, string url) { // Connect to remote activation service. string rem = url + @"/RemoteActivationService.rem"; IActivator remActivator = (IActivator)RemotingServices.Connect(typeof(IActivator), rem); IConstructionReturnMessage crm = remActivator.Activate(ccm); // // The return message's ReturnValue property is the ObjRef for // the remote object. We need to unmarshal it into a local proxy // to which we forward messages. ObjRef objRef = (ObjRef)crm.ReturnValue; _targetTcp = (MarshalByRefObject)RemotingServices.Unmarshal(objRef); }
// 调用代理的类型的方法 public override IMessage Invoke(IMessage msg) { DateTime st = DateTime.Now; // 用lock来防止多线程在一个时间同时操作方法 object returnIMessage = null; IMessage message; lock (obj) { // 如果是调用了构造函数就进入使用下面的代码 if (msg is IConstructionCallMessage) { // 构造函数调用 IConstructionCallMessage constructCallMsg = msg as IConstructionCallMessage; IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg); SetStubData(this, constructionReturnMessage.ReturnValue); returnIMessage = constructionReturnMessage; } // 如果调用方法是一般方法,进入If语句 else { var methodCall = msg as IMethodCallMessage; var methodInfo = methodCall.MethodBase as MethodInfo; // OnBeforeExecute(methodCall); try { var result = methodInfo.Invoke(this.GetUnwrappedServer(), methodCall.InArgs); message = new ReturnMessage(result, null, 0, methodCall.LogicalCallContext, methodCall); // OnAfterExecute(methodCall, message.Properties["__Return"]); returnIMessage = message; } catch (Exception ex) { // OnErrorExecuting(methodCall, ex.InnerException.ToString()); LogHelper.Log.InfoFormat(ex.InnerException == null ? ex.Message : ex.InnerException.Message); returnIMessage = new ReturnMessage(ex, methodCall); } } } return(returnIMessage as IMessage); }
public override IMessage Invoke(IMessage msg) { //消息拦截之后,就会执行这里的方法。 if (msg is IConstructionCallMessage) { IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg); SetStubData(this, constructionReturnMessage.ReturnValue); return(constructionReturnMessage); } else if (msg is IMethodCallMessage) //如果是方法调用(属性也是方法调用的一种) { IMethodCallMessage callMsg = msg as IMethodCallMessage; object[] args = callMsg.Args; IMessage message; try { RealProxyIOCAttribute attr = callMsg.MethodBase.GetAttribute <RealProxyIOCAttribute>(); //没有特性,原路返回 if (attr == null) { object o = callMsg.MethodBase.Invoke(GetUnwrappedServer(), args); message = new ReturnMessage(o, args, args.Length, callMsg.LogicalCallContext, callMsg); return(message); } ///基础属性注入 else if (attr is PropertyBuilderAttribute) { var m = callMsg.MethodBase as MethodInfo; RealProxyIOC si = GetUnwrappedServer() as RealProxyIOC; Type type = si.OverridePropertyType?.FirstOrDefault(a => a.BaseOn(m.ReturnType)) ?? m.ReturnType; object o = Activator.CreateInstance( type, BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { }, null); message = new ReturnMessage(o, args, args.Length, callMsg.LogicalCallContext, callMsg); return(message); } } catch (Exception e) { message = new ReturnMessage(e, callMsg); } } return(msg); }
public override IMessage Invoke(IMessage msg) { //消息拦截之后,就会执行这里的方法。 IConstructionCallMessage constructCallMsg = msg as IConstructionCallMessage; if (constructCallMsg != null) // 如果是构造函数,按原来的方式返回即可。 { IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg); if (constructionReturnMessage != null) { RealProxy.SetStubData(this, constructionReturnMessage.ReturnValue); return(constructionReturnMessage); } } IMethodCallMessage callMsg = msg as IMethodCallMessage; if (callMsg != null) //如果是方法调用(属性也是方法调用的一种) { object[] args = callMsg.Args; IMessage message; try { if (callMsg.MethodName.StartsWith("set_") && args.Length == 1) { //这里检测到是set方法 //在这里切入日志记录 if (!args[0].GetType().IsByRef || args[0].GetType().MemberType == typeof(string).MemberType) { Logger.WriteInfo(string.Format("加载{0}成功,值:{1}", callMsg.MethodName.Substring(callMsg.MethodName.IndexOf("_", StringComparison.Ordinal) + 1), args[0])); } } object o = callMsg.MethodBase.Invoke(GetUnwrappedServer(), args); message = new ReturnMessage(o, args, args.Length, callMsg.LogicalCallContext, callMsg); } catch (Exception e) { message = new ReturnMessage(e, callMsg); } return(message); } return(msg); }
public override IMessage Invoke(IMessage msg) { if (msg is IConstructionCallMessage) { IConstructionCallMessage constructCallMsg = msg as IConstructionCallMessage; IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject(constructCallMsg); RealProxy.SetStubData(this, constructionReturnMessage.ReturnValue); return(constructionReturnMessage); } else if (msg is IMethodCallMessage) { IMethodCallMessage callMsg = msg as IMethodCallMessage; //object[] copiedArgs = Array.CreateInstance(typeof(object), callMsg.Args.Length) as object[]; //callMsg.Args.CopyTo(copiedArgs, 0); var copiedArgs = callMsg.Args; IMessage message; try { var taget = GetUnwrappedServer(); if (taget is IModel) { if (callMsg.MethodName.StartsWith("set_") && copiedArgs.Length == 1) { //透明代理无法调试 //var model = taget as IModel; //if (model.GetInnerChanges()) //{ // model.SetChanges(callMsg.MethodName.Substring(4), copiedArgs[0]); //} } } var returnValue = callMsg.MethodBase.Invoke(taget, copiedArgs); message = new ReturnMessage(returnValue, copiedArgs, copiedArgs.Length, callMsg.LogicalCallContext, callMsg); } catch (Exception e) { message = new ReturnMessage(e, callMsg); } return(message); } return(msg); }
public virtual object GetInstance(IConstructionCallMessage ctorCallMessage, ref IMethodMessage returnMsg) { lock (_padLock) { if (!_ctorMsgs.ContainsKey(ctorCallMessage.ActivationType)) { RealProxy defaultProxy = RemotingServices.GetRealProxy(_target); var x = defaultProxy.InitializeServerObject(ctorCallMessage); IConstructionReturnMessage response = EnterpriseServicesHelper.CreateConstructionReturnMessage(ctorCallMessage, (MarshalByRefObject)this.GetTransparentProxy()); _ctorMsgs.SetValue(ctorCallMessage.ActivationType, response); _instanceMsgs.SetValue(ctorCallMessage.ActivationType, DoObjectInitialize(_target)); //_ctorMsgs.SetValue(ctorCallMessage.ActivationType, InitializeServerObject(ctorCallMessage)); //_instanceMsgs.SetValue(ctorCallMessage.ActivationType, DoObjectInitialize(GetUnwrappedServer())); } returnMsg = _ctorMsgs.GetValue(ctorCallMessage.ActivationType); return(_instanceMsgs.GetValue(ctorCallMessage.ActivationType)); } }
public override IMessage Invoke(IMessage msg) { b += 1; if (msg is IConstructionCallMessage) { IConstructionCallMessage constructCallMsg = msg as IConstructionCallMessage; IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject(constructCallMsg); RealProxy.SetStubData(this, constructionReturnMessage.ReturnValue); return(constructionReturnMessage); } else if (msg is IMethodCallMessage) { IMethodCallMessage callMsg = msg as IMethodCallMessage; object[] copiedArgs = Array.CreateInstance(typeof(object), callMsg.Args.Length) as object[]; callMsg.Args.CopyTo(copiedArgs, 0); //var copiedArgs = callMsg.Args; IMessage message; try { var taget = GetUnwrappedServer(); object returnValue; if (callMsg.MethodName.StartsWith("set_") && copiedArgs.Length == 1) { var method = _serverType.GetMethod("SetChanges", BindingFlags.NonPublic | BindingFlags.Instance); method.Invoke(taget, new object[] { callMsg.MethodName.Substring(4), copiedArgs[0] }); } returnValue = callMsg.MethodBase.Invoke(taget, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static, null, copiedArgs, null); message = new ReturnMessage(returnValue, copiedArgs, copiedArgs.Length, callMsg.LogicalCallContext, callMsg); } catch (Exception e) { message = new ReturnMessage(e, callMsg); } return(message); } return(msg); }
public override IMessage Invoke(IMessage msg) { if (msg is IConstructionCallMessage) { // Initialize a new instance of remote object IConstructionReturnMessage myIConstructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg); ConstructionResponse constructionResponse = new ConstructionResponse(null, (IMethodCallMessage)msg); return(constructionResponse); } IDictionary myIDictionary = msg.Properties; IMessage retMsg; myIDictionary["__Uri"] = m_URI; // Synchronously dispatch messages to server. retMsg = ChannelServices.SyncDispatchMessage(msg); // Pushing return value and OUT parameters back onto stack IMethodReturnMessage mrm = (IMethodReturnMessage)retMsg; return(retMsg); }
internal static object DoCrossContextActivationCallback(object[] args) { IConstructionCallMessage msg = (IConstructionCallMessage)args[0]; IConstructionReturnMessage message2 = null; IMethodReturnMessage message3 = (IMethodReturnMessage)Thread.CurrentContext.GetServerContextChain().SyncProcessMessage(msg); Exception e = null; message2 = message3 as IConstructionReturnMessage; if (message2 == null) { if (message3 != null) { e = message3.Exception; } else { e = new RemotingException(Environment.GetResourceString("Remoting_Activation_Failed")); } message2 = new ConstructorReturnMessage(e, null); ((ConstructorReturnMessage)message2).SetLogicalCallContext((LogicalCallContext)msg.Properties[Message.CallContextKey]); } return(message2); }
public override IMessage Invoke(IMessage msg) { if (msg is IConstructionCallMessage) { IConstructionCallMessage constructCallMsg = msg as IConstructionCallMessage; IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg); SetStubData(this, constructionReturnMessage.ReturnValue); return(constructionReturnMessage); } else { IMethodCallMessage callMsg = msg as IMethodCallMessage; IMessage message; try { object[] args = callMsg.Args; object returnValue; var method = callMsg.MethodBase; string name; name = method.Name; returnValue = proxyServer.Invoke(name, args); message = new ReturnMessage(returnValue, args, args.Length, callMsg.LogicalCallContext, callMsg); } catch (Exception e) { message = new ReturnMessage(e, callMsg); } return(message); } }
public CRMDictionary(IConstructionReturnMessage msg, IDictionary idict) : base( (msg.Exception!=null)? CRMkeysFault : CRMkeysNoFault, idict) { fault = (msg.Exception != null) ; _crmsg = msg; }