Server沒有正常建立,或者是防火牆封鎖端口

解决方案 »

  1.   

    在本机测试的!
    没有开防火墙!server程序:
    using System;
    using System.Runtime.Remoting;
    using System.Runtime.Remoting.Channels;
    using System.Runtime.Remoting.Channels.Http;
    using WroxRemotingHello;namespace RemotingHello
    {
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    class HelloServer
    {   
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
    HttpServerChannel channel = new HttpServerChannel(8080);
    ChannelServices.RegisterChannel(channel);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Hello),"Hi",WellKnownObjectMode.SingleCall);
    Console.WriteLine("hit to exit");
    Console.ReadLine();
    //
    // TODO: 在此处添加代码以启动应用程序
    //
    }
    }
    }
     
    客户端:
    using System;
    using WroxRemotingHello;
    using System.Runtime.Remoting.Channels;
    using System.Runtime.Remoting.Channels.Http;
    namespace HelloClient
    {
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    class Class1
    {
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main(string[] args)
    {
    ChannelServices.RegisterChannel(new HttpClientChannel());
    Hello obj = (Hello)Activator.GetObject(typeof(Hello),"http://localhost:8080/Hi");
    if (obj == null)
    {
    Console.WriteLine("could not locate server");
    return;
    } for(int i = 0;i<5;i++)
    {
    Console.WriteLine(obj.Greeting("Christian"));
    }
    //
    // TODO: 在此处添加代码以启动应用程序
    //
    }
    }
    }
      

  2.   

    WroxRemotingHello类库:using System;namespace WroxRemotingHello
    {
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    public class Hello:MarshalByRefObject
    {
    public Hello()
    {
    Console.WriteLine("Constructor called"); //
    // TODO: 在此处添加构造函数逻辑
    //
    }
    ~Hello()
    {
    Console.WriteLine("Destructor called");
    } public string Greeting(string name)
    {
    Console.WriteLine("Greeting called");
    return "Hello,"+name;
    }
    }
    }
      

  3.   

    靠!行了!第一次做!~闹笑话了!呵呵!原来server程序要一直运行!感谢qimini(循序渐进)