public override RealProxy CreateProxy(ObjRef objRef1, Type serverType, object serverObject, Context serverContext) { MyProxy myCustomProxy = new MyProxy(serverType); if (serverContext != null) { RealProxy.SetStubData(myCustomProxy, serverContext); } if ((!serverType.IsMarshalByRef) && (serverContext == null)) { throw new RemotingException("Bad Type for CreateProxy"); } return(myCustomProxy); }
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); }