Изучаю remoting. Мне необходимо организовать связь между двумя remoting серверами. Клиент передает данные на обработку 1 серверу, который далее передает их на 2 сервер. Второй обработав возвращает... Не получается правильно организовать взаимодействие между 1 и 2 сервером? Клиент | Код |
using System; using System.Data; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp; using System.Runtime.Remoting.Activation;
#endregion
namespace TestRemoting { class Program { static void Main(string[] args) { ChannelServices.RegisterChannel(new TcpClientChannel(),false); TestMetod obj = (TestMetod)Activator.GetObject(typeof(TestMetod), "tcp://localhost:8086/Hi"); DataTable __table1 = new DataTable("Test");
__table1.Columns.Add("ID", typeof(int)); __table1.Columns.Add("TEXT", typeof(string));
DataRow __row = __table1.NewRow(); __row["ID"] = 1; __row["TEXT"] = "Строка1"; __table1.Rows.Add(__row);
__row = __table1.NewRow(); __row["ID"] = 2; __row["TEXT"] = "Строка2"; __table1.Rows.Add(__row);
DataTable __table2 = obj._Test_table(__table1); Console.ReadLine(); } }
public class TestMetod : System.MarshalByRefObject { public DataTable _Test_table(DataTable __table) { return __table; } } }
|
Сервер1 | Код | using System; using System.Collections; using System.Data; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp;
namespace TestRemoting { class Program { static void Main(string[] args) { Console.WriteLine("СЕРВЕР1"); TcpServerChannel tcpChannel = new TcpServerChannel(8086); ChannelServices.RegisterChannel(tcpChannel,false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(TestMetod), "Hi", WellKnownObjectMode.SingleCall); System.Console.WriteLine("Enter для остановки сервера"); System.Console.ReadLine(); } } public class TestMetod : System.MarshalByRefObject { public DataTable _Test_table(DataTable __table) { ChannelServices.RegisterChannel(new TcpClientChannel(), false);
TestMetod2 obj2 = (TestMetod2)Activator.GetObject(typeof(TestMetod2), "tcp://localhost:9086/Hi");
if (obj2 == null) { Console.WriteLine("сервер не найден"); return __table; } return obj2._Test_table(__table); } }
public class TestMetod2 : System.MarshalByRefObject { public DataTable _Test_table(DataTable __table) { return __table; } } }
|
Сервер2 | Код | using System; using System.Collections; using System.Data; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Channels.Tcp;
namespace TestRemoting { class Program { static void Main(string[] args) { TcpServerChannel tcpChannel = new TcpServerChannel(9086);
Console.WriteLine("СЕРВЕР2"); ChannelServices.RegisterChannel(tcpChannel,false); RemotingConfiguration.RegisterWellKnownServiceType(typeof(TestMetod2), "Hi", WellKnownObjectMode.SingleCall); System.Console.WriteLine("Enter для остановки СЕРВЕРа2"); System.Console.ReadLine(); } }
public class TestMetod2 : System.MarshalByRefObject { public DataTable _Test_table(DataTable __table) { Console.WriteLine("Вызов таблицы был обработан успешно.");
DataRow __row = __table.NewRow(); __row["ID"] = 3; __row["TEXT"] = "Новая строка"; __table.Rows.Add(__row);
__row = __table.NewRow(); __row["ID"] = 4; __row["TEXT"] = "Новая строка"; __table.Rows.Add(__row); return __table; } } }
|
|