远程对象
using System;
using System.Collections.Generic;
using System.Text;namespace TestRemoteObject
{
public class RemoteObject
{
public int Add(int a, int b)
{
return a + b;
}
}
} 服务端
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
namespace TestRemotingConsoleServer
{
class Program
{
static void Main(string[] args)
{
//新建一个TCP信道
TcpChannel tc = new TcpChannel(9999);
//注册TCP信道
ChannelServices.RegisterChannel(tc, false);
//注册知名对象
RemotingConfiguration.RegisterWellKnownServiceType(typeof(TestRemoteObject.RemoteObject), "RemoteObject", WellKnownObjectMode.SingleCall);
Console.ReadLine(); }
}
}客服端
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TestRemoteObject.RemoteObject mo = (TestRemoteObject.RemoteObject)Activator.GetObject(typeof(TestRemoteObject.RemoteObject), "tcp://localhost:9999/RemoteObject");
Response.Write(mo.Add(1, 2));
}
}
错误信息
异常详细信息: System.Runtime.Remoting.RemotingException: 试图创建未绑定类型的代理。源错误:
行 13: protected void Page_Load(object sender, EventArgs e)
行 14: {
行 15: TestRemoteObject.RemoteObject mo = (TestRemoteObject.RemoteObject)Activator.GetObject(typeof(TestRemoteObject.RemoteObject), "tcp://localhost:9999/RemoteObject");
行 16: Response.Write(mo.Add(1, 2));
行 17: }
源文件: c:\Users\HP\Documents\Visual Studio 2005\WebSites\TestRemote\Default.aspx.cs 行: 15
using System;
using System.Collections.Generic;
using System.Text;namespace TestRemoteObject
{
public class RemoteObject
{
public int Add(int a, int b)
{
return a + b;
}
}
} 服务端
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting;
namespace TestRemotingConsoleServer
{
class Program
{
static void Main(string[] args)
{
//新建一个TCP信道
TcpChannel tc = new TcpChannel(9999);
//注册TCP信道
ChannelServices.RegisterChannel(tc, false);
//注册知名对象
RemotingConfiguration.RegisterWellKnownServiceType(typeof(TestRemoteObject.RemoteObject), "RemoteObject", WellKnownObjectMode.SingleCall);
Console.ReadLine(); }
}
}客服端
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TestRemoteObject.RemoteObject mo = (TestRemoteObject.RemoteObject)Activator.GetObject(typeof(TestRemoteObject.RemoteObject), "tcp://localhost:9999/RemoteObject");
Response.Write(mo.Add(1, 2));
}
}
错误信息
异常详细信息: System.Runtime.Remoting.RemotingException: 试图创建未绑定类型的代理。源错误:
行 13: protected void Page_Load(object sender, EventArgs e)
行 14: {
行 15: TestRemoteObject.RemoteObject mo = (TestRemoteObject.RemoteObject)Activator.GetObject(typeof(TestRemoteObject.RemoteObject), "tcp://localhost:9999/RemoteObject");
行 16: Response.Write(mo.Add(1, 2));
行 17: }
源文件: c:\Users\HP\Documents\Visual Studio 2005\WebSites\TestRemote\Default.aspx.cs 行: 15
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货