未处理的“System.Net.Sockets.SocketException”类型的异常出现在 mscorlib.dll 中。其他信息: 由于目标机器积极拒绝,无法连接。感谢帮 Server沒有正常建立,或者是防火牆封鎖端口 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在本机测试的!没有开防火墙!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: 在此处添加代码以启动应用程序 // } }} 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; } }} 靠!行了!第一次做!~闹笑话了!呵呵!原来server程序要一直运行!感谢qimini(循序渐进) 关于ZedGraph C#调用C++写的DLL的问题 三层问题 界面中的控件对应C#中???控件 套打换页!!!!!!!!!!!!!!!! 提取子字符串的问题 大家帮我看看强类型DataSet的问题吧 关于多线程的新手问题,急!!!!!!!!!!!!! vs封装开发的程序和sql数据库 datagridview 多行选择问题 大虾们,来指点以下小弟吧(真的谢谢大家了) 如何在C#中读写INI文件?
没有开防火墙!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: 在此处添加代码以启动应用程序
//
}
}
}
{
/// <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;
}
}
}