using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Interfaces { public interface ICustomer { void setName(string name); string getName(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Interfaces; namespace Implementation { public class Customer : MarshalByRefObject, ICustomer { string name; public Customer() { name = "harris"; } public void setName(string name) { this.name = name; } public string getName() { return name; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Reflection; namespace Server { class Program { static void Main(string[] args) { System.Reflection.Assembly newAssembly = System.Reflection.Assembly.LoadFrom(@"C:\Documents and Settings\BP FANTONI\Desktop\RemotingApp3\Implementation\bin\Debug\Implementation.dll"); Object o = newAssembly.CreateInstance("Implementation.Customer"); //Assembly a = Assembly.LoadFrom("C:\\Documents and Settings\\BP FANTONI\\Desktop\\RemotingApp3\\Implementation\\bin\\Debug\\Implementation.dll"); //Module m = newAssembly.GetModule("Implementation.dll"); Type t = o.GetType(); System.Runtime.Remoting.Channels.Tcp.TcpServerChannel channel = new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel(8080); ChannelServices.RegisterChannel(channel, false); RemotingConfiguration.RegisterWellKnownServiceType(t, "customer", WellKnownObjectMode.Singleton); //RemotingConfiguration.ApplicationName = "remoteserver"; //RemotingConfiguration.RegisterActivatedServiceType(t); Console.WriteLine("Press enter to exit."); Console.Read(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Interfaces; using System.Runtime.Remoting; using System.Runtime.Remoting.Activation; using System.Runtime.Remoting.Channels; namespace Client { class Program { static void Main(string[] args) { System.Runtime.Remoting.Channels.Tcp.TcpClientChannel channel = new System.Runtime.Remoting.Channels.Tcp.TcpClientChannel(); ChannelServices.RegisterChannel(channel, false); ICustomer cust = (ICustomer)Activator.GetObject(typeof(ICustomer), "tcp://localhost:8080/customer"); //ICustomer cust = (ICustomer)Activator.CreateInstance(typeof(ICustomer), null, new object[] {new UrlAttribute("tcp://localhost:8080")} ); RemotingConfiguration.RegisterActivatedClientType(typeof(ICustomer), "tcp://localhost:8080/remoteserver"); //ICustomer cust = n Console.WriteLine("Name: " + cust.getName()); Console.Read(); } } }