Client.cs
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:1k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Runtime.Remoting;
  3. using System.Runtime.Remoting.Channels;
  4. using System.Runtime.Remoting.Channels.Http;
  5. using MathLibrary;
  6. namespace MathClient
  7. {
  8. class ClientMain
  9. {
  10. static void Main(string[] args)
  11. {
  12.          // Create and register the channel. The default channel ctor 
  13.          // does not open a port, so we can't use this to receive messsages.
  14. HttpClientChannel channel = new HttpClientChannel();
  15.          ChannelServices.RegisterChannel(channel);
  16.          // Go get the remote object
  17.          Object remoteObj = Activator.GetObject(
  18.                                typeof(MathLibrary.SimpleMath),
  19.                                "http://localhost:13101/myURI.soap"
  20.                             );
  21.          // Cast the returned proxy to the SimpleMath type
  22.          SimpleMath math = (SimpleMath)remoteObj;
  23.          // Use the remote object
  24.          Console.WriteLine("5 + 2 = {0}", math.Add(5,2));
  25.          Console.WriteLine("5 - 2 = {0}", math.Subtract(5,2));
  26.          // Ask user to press enter
  27.          Console.Write("Press enter to end");
  28.          Console.ReadLine();
  29.       }
  30. }
  31. }