static void Main(string[] args) { HproseClassManager.Register(typeof(User), "User"); client = new HproseHttpClient("http://localhost:2012/"); List <User> users = new List <User>(); User user1 = new User(); user1.name = "李雷"; user1.age = 32; user1.male = true; user1.friends = new List <User>(); User user2 = new User(); user2.name = "韩梅梅"; user2.age = 31; user2.male = false; user2.friends = new List <User>(); user1.friends.Add(user2); user2.friends.Add(user1); users.Add(user1); users.Add(user2); Func <List <User>, List <User> > SendUsers = userList => client.Invoke <List <User> >("sendUsers", new object[] { userList }); Hello(); MemoryStream stream = (MemoryStream)HproseFormatter.Serialize(SendUsers(users)); Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray())); Console.ReadLine(); }
private void Button_Click_1(object sender, RoutedEventArgs e) { //HproseClient.SynchronizationContext = SynchronizationContext.Current; HproseHttpClient client = new HproseHttpClient("http://localhost:2012/"); ISendUsers proxyObject = client.UseService <ISendUsers>(); var SendUsers = client.GetFunc <List <User>, List <User> >("sendUsers"); var AsyncSendUsers = client.GetAsyncAction <List <User>, HproseCallback1 <List <User> > >("sendUsers"); List <User> users = new List <User>(); User user1 = new User(); user1.name = "李雷"; user1.age = 32; user1.male = true; user1.friends = new List <User>(); User user2 = new User(); user2.name = "韩梅梅"; user2.age = 31; user2.male = false; user2.friends = new List <User>(); user1.friends.Add(user2); user2.friends.Add(user1); users.Add(user1); users.Add(user2); MemoryStream stream = HproseFormatter.Serialize(users); byte[] bytes = stream.ToArray(); System.Windows.Browser.HtmlPage.Window.Eval("alert('" + UTF8Encoding.UTF8.GetString(bytes, 0, bytes.Length) + "')"); HproseCallback1 <List <User> > callback = result => { MemoryStream s = HproseFormatter.Serialize(result); byte[] b = s.ToArray(); System.Windows.Browser.HtmlPage.Window.Eval("alert('" + UTF8Encoding.UTF8.GetString(b, 0, b.Length) + "')"); }; proxyObject.SendUsers(users, callback); AsyncSendUsers(users, callback); new Thread(() => { byte[] b = proxyObject.SendUsersRaw(users); Dispatcher.BeginInvoke(() => { System.Windows.Browser.HtmlPage.Window.Eval("alert('" + UTF8Encoding.UTF8.GetString(b, 0, b.Length) + "')"); }); MemoryStream ss = HproseFormatter.Serialize(SendUsers(users)); byte[] bb = ss.ToArray(); Dispatcher.BeginInvoke(() => { System.Windows.Browser.HtmlPage.Window.Eval("alert('" + UTF8Encoding.UTF8.GetString(bb, 0, bb.Length) + "')"); }); string result = proxyObject.Hello("World"); Dispatcher.BeginInvoke(() => { System.Windows.Browser.HtmlPage.Window.Eval("alert('" + result + "')"); }); }).Start(); }
static void Main(string[] args) { DateTime start, end; ArrayList users = new ArrayList(); User user1 = new User(); user1.name = "李雷"; user1.age = 32; user1.male = true; user1.friends = new List <User>(); User user2 = new User(); user2.name = "韩梅梅"; user2.age = 31; user2.male = false; user2.friends = new List <User>(); user1.friends.Add(user2); user2.friends.Add(user1); users.Add(user1); users.Add(user2); MemoryStream s = HproseFormatter.Serialize(users, HproseMode.FieldMode); Console.WriteLine(Encoding.UTF8.GetString(s.ToArray())); s.Position = 0; s = HproseFormatter.Serialize( HproseFormatter.Unserialize( s)); Console.WriteLine(Encoding.UTF8.GetString(s.ToArray())); s.Position = 0; List <User> users3 = HproseFormatter.Unserialize <List <User> >(s); s = HproseFormatter.Serialize(users3); Console.WriteLine(Encoding.UTF8.GetString(s.ToArray())); s.Position = 0; ArrayList users4 = HproseFormatter.Unserialize <ArrayList>(s); s = HproseFormatter.Serialize(users4); Console.WriteLine(Encoding.UTF8.GetString(s.ToArray())); s.Position = 0; s = HproseFormatter.Serialize(new IntEnum[] { IntEnum.First, IntEnum.Second, IntEnum.Third }); Console.WriteLine(Encoding.UTF8.GetString(s.ToArray())); s.Position = 0; LongEnum[] longEnums = HproseFormatter.Unserialize <LongEnum[]>(s); s = HproseFormatter.Serialize(longEnums); Console.WriteLine(Encoding.UTF8.GetString(s.ToArray())); s.Position = 0; UShortEnum[] ushortEnums = HproseFormatter.Unserialize <UShortEnum[]>(s); s = HproseFormatter.Serialize(ushortEnums); Console.WriteLine(Encoding.UTF8.GetString(s.ToArray())); s.Position = 0; start = DateTime.Now; for (int i = 0; i < 10000; i++) { HproseFormatter.Serialize(users3); } end = DateTime.Now; Console.WriteLine(end.Ticks - start.Ticks); start = DateTime.Now; for (int i = 0; i < 10000; i++) { HproseFormatter.Serialize(users4); } end = DateTime.Now; Console.WriteLine(end.Ticks - start.Ticks); start = DateTime.Now; for (int i = 0; i < 10000; i++) { HproseFormatter.Serialize(users3); } end = DateTime.Now; Console.WriteLine(end.Ticks - start.Ticks); start = DateTime.Now; for (int i = 0; i < 10000; i++) { HproseFormatter.Serialize(users4); } end = DateTime.Now; Console.WriteLine(end.Ticks - start.Ticks); Console.ReadKey(); }