我做了一个Remoting的例子,在本机可以读取数据,但在局域网中其它的电脑就出现了异常,
错误提示:服务器已拒绝客户端凭据..======server代码===============
private void Form1_Load(object sender, EventArgs e)
        {
            ChannelServices.RegisterChannel(new TcpServerChannel(9999), true);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemotingTest.Remote), "liao5930", WellKnownObjectMode.Singleton);
        }=========Client端代码=========
private void Form1_Load(object sender, EventArgs e)
        {
            ChannelServices.RegisterChannel(new TcpClientChannel(), true);
            RemotingTest.Remote obj = (RemotingTest.Remote)Activator.GetObject(typeof(RemotingTest.Remote), "tcp://192.168.100.101:9999/liao5930");
            this.dataGridView1.DataSource = obj.datable();
        }
=========RemotingTest代码================
SqlConnection con;
        DataSet ds;
        SqlDataAdapter da;
        string conStr = "Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=ERPSystem;Data Source=LIAO5930;packet size=4096";
        string queryStr = "select   *   from   login";
        public DataTable datable()
        {
            using (con = new SqlConnection(conStr))
            {
                using (da = new SqlDataAdapter(queryStr, con))
                {
                    ds = new DataSet();
                    da.Fill(ds, "Categories");                    return ds.Tables["Categories"];
                }
            }
        }麻烦大家帮忙看看,谢谢了

解决方案 »

  1.   

    配置文件中加入认证:
    http://hi.baidu.com/liupras/blog/item/90e76d5477007350574e0078.html
    http://www.cnblogs.com/scucj/archive/2007/05/09/740808.html
    http://www.cnblogs.com/scucj/archive/2007/11/19/740813.html#964078
      

  2.   

    “服务器已拒绝客户端凭据”该问题主要出现在VS2005及以后的版本。该问题主要是安全设置问题,出现在“向信道服务注册信道”的时候。在VS2005以前的版本,“向信道服务注册信道”只需要System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel),到了VS2005及以后的版本(VS2008)就改为了System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan,true/false),查看MSDN的帮组,显示后面的布尔变量所包含的意思为:
    ensureSecurity 
    类型:System..::.Boolean如果启用了安全,则为 true;否则为 false。将该值设置为 false 将不会使在 TCP 或 IPC 信道上所做的安全设置无效。有关详细信息,请参见“备注”。
    解决“服务器已拒绝客户端凭据”最简单的办法就是把客户端和服务端的RegisterChannel都改为“RegisterChannel(chan,false)”就可以了
    ChannelServices.RegisterChannel(new TcpServerChannel(9999), true); 
    ==>
    ChannelServices.RegisterChannel(new TcpServerChannel(9999), false); ChannelServices.RegisterChannel(new TcpClientChannel(), true); 
    ==>
    ChannelServices.RegisterChannel(new TcpClientChannel(), false); 
      

  3.   

    谢谢wangsaokui,改为false就能读取数据,但正如你所说改为false后安全设置会无效
    那如果要用true则怎么办呢?
      

  4.   

    http://www.cnblogs.com/bookwormzju/archive/2006/09/26/515030.html
    如果在Internet上,建议改成HTTP通道
      

  5.   

    http://msdn.microsoft.com/zh-cn/library/aa302391.aspx