public IMessage LocalInvoke(IMessage reqMsg) { IMessage message = null; if (reqMsg is IConstructionCallMessage) { this.ActivateProxy(); if (this._filterConstructors) { this._filterConstructors = false; RealProxy.SetStubData(this, this._token); } if (((IConstructionCallMessage)reqMsg).ArgCount > 0) { throw new ServicedComponentException(Resource.FormatString("ServicedComponentException_ConstructorArguments")); } MarshalByRefObject transparentProxy = (MarshalByRefObject)this.GetTransparentProxy(); return(EnterpriseServicesHelper.CreateConstructionReturnMessage((IConstructionCallMessage)reqMsg, transparentProxy)); } if (reqMsg is IMethodCallMessage) { message = this.HandleSpecialMethods(reqMsg); if (message != null) { return(message); } if ((base.GetUnwrappedServer() == null) || (((IntPtr)RealProxy.GetStubData(this)) == NegativeOne)) { throw new ObjectDisposedException("ServicedComponent"); } bool flag = this.SendMethodCall(reqMsg); try { message = RemotingServices.ExecuteMessage((MarshalByRefObject)this.GetTransparentProxy(), (IMethodCallMessage)reqMsg); if (flag) { this.SendMethodReturn(reqMsg, ((IMethodReturnMessage)message).Exception); } } catch (Exception exception) { if ((exception is NullReferenceException) || (exception is SEHException)) { throw; } if (flag) { this.SendMethodReturn(reqMsg, exception); } throw; } } return(message); }
public static void test() { IAnimal animal = null; DynamicProxy dynamicProxy = new DynamicProxy(typeof(Cicada)); animal = (IAnimal)(dynamicProxy.GetTransparentProxy()); // Get stubdata. Console.WriteLine("GetStubData = " + RealProxy.GetStubData(dynamicProxy).ToString()); animal.Eating(); //Assert.Pass(); }
public static void Main() { Console.WriteLine(""); Console.WriteLine("CustomProxy Sample"); Console.WriteLine("================"); Console.WriteLine(""); // Create an instance of MyProxy. MyProxy myProxyInstance = new MyProxy(typeof(CustomServer)); // Get a CustomServer proxy. CustomServer myHelloServer = (CustomServer)myProxyInstance.GetTransparentProxy(); // Get stubdata. Console.WriteLine("GetStubData = " + RealProxy.GetStubData(myProxyInstance).ToString()); // Get ProxyType. Console.WriteLine("Type of object represented by RealProxy is :" + myProxyInstance.GetProxiedType()); myHelloServer.HelloMethod("RealProxy Sample"); Console.WriteLine(""); // Get a reference object from server. Console.WriteLine("Create an objRef object to be marshalled across Application Domains..."); ObjRef CustomObjRef = myProxyInstance.CreateObjRef(typeof(CustomServer)); Console.WriteLine("URI of 'ObjRef' object = " + CustomObjRef.URI); }