public static object CreateProxyForType(Type type) { // Called by the runtime when creating an instance of a type // that has been registered as remotely activated. // First of all check for remote activation. If the object is not remote, then // it may be contextbound. ActivatedClientTypeEntry activatedEntry = RemotingConfiguration.IsRemotelyActivatedClientType(type); if (activatedEntry != null) { return(RemotingServices.CreateClientProxy(activatedEntry, null)); } WellKnownClientTypeEntry wellknownEntry = RemotingConfiguration.IsWellKnownClientType(type); if (wellknownEntry != null) { return(RemotingServices.CreateClientProxy(wellknownEntry)); } if (type.IsContextful) { return(RemotingServices.CreateClientProxyForContextBound(type, null)); } #if !NET_2_1 if (type.IsCOMObject) { return(RemotingServices.CreateClientProxyForComInterop(type)); } #endif return(null); }
public static object CreateProxyFromAttributes(Type type, object[] activationAttributes) { string activationUrl = null; foreach (object attr in activationAttributes) { if (!(attr is IContextAttribute)) { throw new RemotingException("Activation attribute does not implement the IContextAttribute interface"); } if (attr is UrlAttribute) { activationUrl = ((UrlAttribute)attr).UrlValue; } } if (activationUrl != null) { return(RemotingServices.CreateClientProxy(type, activationUrl, activationAttributes)); } ActivatedClientTypeEntry activatedEntry = RemotingConfiguration.IsRemotelyActivatedClientType(type); if (activatedEntry != null) { return(RemotingServices.CreateClientProxy(activatedEntry, activationAttributes)); } if (type.IsContextful) { return(RemotingServices.CreateClientProxyForContextBound(type, activationAttributes)); } return(null); }
static void Main() { try { ChannelServices.RegisterChannel(new TcpChannel()); RemotingConfiguration.RegisterActivatedClientType( typeof(MyServerImpl), "tcp://localhost:8085"); MyServerImpl myObject = new MyServerImpl(); for (int i = 0; i <= 4; i++) { Console.WriteLine(myObject.MyMethod("invoke the server method " + (i + 1) + " time.")); } // <Snippet1> // Check whether the 'MyServerImpl' type is registered as // a remotely activated client type. ActivatedClientTypeEntry myActivatedClientEntry = RemotingConfiguration.IsRemotelyActivatedClientType( typeof(MyServerImpl)); Console.WriteLine("The Object type is " + myActivatedClientEntry.ObjectType); Console.WriteLine("The Application Url is " + myActivatedClientEntry.ApplicationUrl); // </Snippet1> } catch (Exception e) { Console.WriteLine(e.Message); } }
public override bool IsContextOK(Context ctx, IConstructionCallMessage ctorMsg) { if (RemotingConfigHandler.Info == null) { return(true); } RuntimeType runtimeType = ctorMsg.ActivationType as RuntimeType; if (runtimeType == null) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); } WellKnownClientTypeEntry wellKnownClientTypeEntry = RemotingConfigHandler.IsWellKnownClientType(runtimeType); string text = (wellKnownClientTypeEntry == null) ? null : wellKnownClientTypeEntry.ObjectUrl; if (text != null) { ctorMsg.Properties["Connect"] = text; return(false); } ActivatedClientTypeEntry activatedClientTypeEntry = RemotingConfigHandler.IsRemotelyActivatedClientType(runtimeType); string text2 = null; if (activatedClientTypeEntry == null) { object[] callSiteActivationAttributes = ctorMsg.CallSiteActivationAttributes; if (callSiteActivationAttributes != null) { for (int i = 0; i < callSiteActivationAttributes.Length; i++) { UrlAttribute urlAttribute = callSiteActivationAttributes[i] as UrlAttribute; if (urlAttribute != null) { text2 = urlAttribute.UrlValue; } } } if (text2 == null) { return(true); } } else { text2 = activatedClientTypeEntry.ApplicationUrl; } string value; if (!text2.EndsWith("/", StringComparison.Ordinal)) { value = text2 + "/RemoteActivationService.rem"; } else { value = text2 + "RemoteActivationService.rem"; } ctorMsg.Properties["Remote"] = value; return(false); }
public static void Main() { // Register TCP Channel. ChannelServices.RegisterChannel(new TcpChannel()); //<snippet2> // Create activated client type entry. ActivatedClientTypeEntry myActivatedClientTypeEntry = new ActivatedClientTypeEntry(typeof(HelloServer), "tcp://localhost:8082"); //</snippet2> // Register type on client to activate it on the server. RemotingConfiguration.RegisterActivatedClientType( myActivatedClientTypeEntry); // Activate a client activated object type. HelloServer myHelloServer = new HelloServer("ParameterString"); //<snippet3> // Print the object type. Console.WriteLine( "Object type of client activated object: " + myActivatedClientTypeEntry.ObjectType.ToString()); //</snippet3> //<snippet4> // Print the application URL. Console.WriteLine( "Application url where the type is activated: " + myActivatedClientTypeEntry.ApplicationUrl); //</snippet4> //<snippet5> // Print the string representation of the type entry. Console.WriteLine( "Type name, assembly name and application URL " + "of the remote object: " + myActivatedClientTypeEntry.ToString()); //</snippet5> // Print a blank line. Console.WriteLine(); // Check that server was located. if (myHelloServer == null) { Console.WriteLine("Could not locate server"); } else { Console.WriteLine("Calling remote object"); Console.WriteLine(myHelloServer.HelloMethod("Bill")); } }
public override bool IsContextOK(Context ctx, IConstructionCallMessage ctorMsg) { if (RemotingConfigHandler.Info == null) { return(true); } RuntimeType svrType = ctorMsg.ActivationType as RuntimeType; if (svrType == (RuntimeType)null) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType")); } WellKnownClientTypeEntry knownClientTypeEntry = RemotingConfigHandler.IsWellKnownClientType(svrType); string str1 = knownClientTypeEntry == null ? (string)null : knownClientTypeEntry.ObjectUrl; if (str1 != null) { ctorMsg.Properties[(object)"Connect"] = (object)str1; return(false); } ActivatedClientTypeEntry activatedClientTypeEntry = RemotingConfigHandler.IsRemotelyActivatedClientType(svrType); string str2 = (string)null; if (activatedClientTypeEntry == null) { object[] activationAttributes = ctorMsg.CallSiteActivationAttributes; if (activationAttributes != null) { for (int index = 0; index < activationAttributes.Length; ++index) { UrlAttribute urlAttribute = activationAttributes[index] as UrlAttribute; if (urlAttribute != null) { str2 = urlAttribute.UrlValue; } } } if (str2 == null) { return(true); } } else { str2 = activatedClientTypeEntry.ApplicationUrl; } string str3 = str2.EndsWith("/", StringComparison.Ordinal) ? str2 + "RemoteActivationService.rem" : str2 + "/RemoteActivationService.rem"; ctorMsg.Properties[(object)"Remote"] = (object)str3; return(false); }
public static object CreateProxyForType(Type type) { ActivatedClientTypeEntry activatedClientTypeEntry = RemotingConfiguration.IsRemotelyActivatedClientType(type); if (activatedClientTypeEntry != null) { return(RemotingServices.CreateClientProxy(activatedClientTypeEntry, null)); } WellKnownClientTypeEntry wellKnownClientTypeEntry = RemotingConfiguration.IsWellKnownClientType(type); if (wellKnownClientTypeEntry != null) { return(RemotingServices.CreateClientProxy(wellKnownClientTypeEntry)); } if (type.IsContextful) { return(RemotingServices.CreateClientProxyForContextBound(type, null)); } return(null); }
private static string GetApplicationURL(Type Type) { ActivatedClientTypeEntry entry = null; foreach (ActivatedClientTypeEntry temp in RemotingConfiguration.GetRegisteredActivatedClientTypes()) { if (temp.TypeName.Equals(Type.FullName)) { entry = temp; break; } } if (entry == null) { throw new ArgumentException(String.Format("Type {0} not found.", Type.FullName)); } return(entry.ApplicationUrl); }
static void Main() { try { ChannelServices.RegisterChannel(new TcpChannel()); RemotingConfiguration.RegisterActivatedClientType( typeof(MyServerImpl), "tcp://localhost:8085"); MyServerImpl myObject = new MyServerImpl(); for (int i = 0; i <= 4; i++) { Console.WriteLine(myObject.MyMethod("invoke the server method ")); } // Get the assembly for the 'MyServerImpl' object. // <Snippet1> Assembly myAssembly = Assembly.GetAssembly(typeof(MyServerImpl)); AssemblyName myName = myAssembly.GetName(); // Check whether the 'MyServerImpl' type is registered as // a remotely activated client type. ActivatedClientTypeEntry myActivatedClientEntry = RemotingConfiguration.IsRemotelyActivatedClientType( (typeof(MyServerImpl)).FullName, myName.Name); Console.WriteLine("The Object type : " + myActivatedClientEntry.ObjectType); Console.WriteLine("The Application Url : " + myActivatedClientEntry.ApplicationUrl); if (myActivatedClientEntry != null) { Console.WriteLine("Object is client activated"); } else { Console.WriteLine("Object is not client activated"); } // </Snippet1> } catch (Exception e) { Console.WriteLine(e.Message); } }
public static void Main() { ChannelServices.RegisterChannel(new TcpChannel()); ActivatedClientTypeEntry myActivatedClientTypeEntry = new ActivatedClientTypeEntry(typeof(HelloServer), "tcp://localhost:8082"); // Register 'HelloServer' Type on the client end so that it can be // activated on the server. RemotingConfiguration.RegisterActivatedClientType( myActivatedClientTypeEntry); // Obtain a proxy object for the remote object. HelloServer myHelloServer = new HelloServer("ParameterString"); if (myHelloServer == null) { System.Console.WriteLine("Could not locate server"); } else { Console.WriteLine("Calling remote object"); Console.WriteLine(myHelloServer.HelloMethod("Bill")); } }
public static void RegisterActivatedClientType(ActivatedClientTypeEntry entry) { }
public static void Main() { // Register TCP Channel. ChannelServices.RegisterChannel(new TcpChannel()); // Create activated client type entry. ActivatedClientTypeEntry myActivatedClientTypeEntry = new ActivatedClientTypeEntry(typeof(HelloServer), "tcp://localhost:8082"); // Register type on client to activate it on the server. RemotingConfiguration.RegisterActivatedClientType( myActivatedClientTypeEntry); // Activate a client activated object type. HelloServer myHelloServer = new HelloServer("ParameterString"); // Print the object type. Console.WriteLine( "Object type of client activated object: " + myActivatedClientTypeEntry.ObjectType.ToString()); myHelloServer.HelloMethod("Bill"); for (int i = 1; i < 10; i++) { myHelloServer.Hello("You name"); } myHelloServer.HelloWorld(); int sum = myHelloServer.Sum(4, 5); Console.WriteLine(sum); Console.ReadLine(); //// Print the application URL. //Console.WriteLine( // "Application url where the type is activated: " + // myActivatedClientTypeEntry.ApplicationUrl); //// Print the string representation of the type entry. //Console.WriteLine( // "Type name, assembly name and application URL " + // "of the remote object: " + // myActivatedClientTypeEntry.ToString()); //// Print a blank line. //Console.WriteLine(); //// Check that server was located. //if (myHelloServer == null) //{ // Console.WriteLine("Could not locate server"); //} //else //{ // Console.WriteLine("Calling remote object"); // Console.WriteLine(myHelloServer.HelloMethod("Bill")); //} }