连接尝试失败,因为连接方没有正确响应... .NET Remoting

A connection attempt failed because the connected party did not properly respond... .NET Remoting

我在两台电脑上有两个应用程序。这些应用程序通过 .NET Remoting 进行通信。 第一个应用程序充当访问数据库的服务器,第二个应用程序充当客户端并将该数据写入另一个数据库。

当我的客户端在服务器上的远程对象上调用某些方法时,出现以下错误:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.200.60:31621

嗯,很好,但我对 IP 地址 192.168.200.60 一无所知,我正在连接到 172.XXX.XXX.216。似乎有两个网络连接,并且在某种程度上不适合远程处理。

ipcongif 在我的服务器上看起来像这样:

完全相同的解决方案适用于另外 3 台 Windows 2000、Windows XP 和 Windows 7 的计算机。服务器是在 .NET Framework 2.0 中开发的。

客户端和服务器有共同的DLL库,有两个接口ICAOFactory和ICAO。首先,我创建工厂 CAOFactory,它有方法 CreateCAO,它是 returns CAO 对象。当我调用 ICAO 对象的某个方法时,它失败了。

这是我的服务器应用程序注册远程对象的方式:

TcpChannel channel = new TcpChannel(31621); 
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(My_Server.CAOFactory), "My_Server", WellKnownObjectMode.Singleton);

这是我的客户创建远程对象的方式:

My_Share.ICAOFactory srvFactory;
My_Share.ICAO srvCAO;

srvFactory = (My_Share.ICAOFactory)Activator.GetObject(typeof(Foerster_Share.ICAOFactory), "tcp://" + ip + ":" + port + "/My_Server");
srvCAO = srvFactory.CreateCAO(); // no problem
srvCAO.Init(dateTime); // problem

这是我的 CAOFactory 对象:

public class CAOFactory : MarshalByRefObject, ICAOFactory
{
    public ICAO CreateCAO()
    {
        ICAO CAOObj = new CAO();
        return CAOObj;
    }

    public void GetClientCount(out long clientCountSum, out long clientCountMax, out long clientCountActive)
    {
        clientCountSum = 0;
        clientCountMax = 0;
        clientCountActive = 0;
        return;
    }

    public override object InitializeLifetimeService()
    {
        return null;
    }
}

这是我的 CAO 对象:

public class CAO : MarshalByRefObject, ICAO
{
    public void Ping()
    {
        return;
    }

    DateTime dtInit;

    public void Init(DateTime dt)
    {
        dtInit = dt;
    }

    // + some other methods
}

非常感谢任何帮助!

您的目标 .NET 版本是什么?

我认为你需要使用 TcpChannel 的 bindTo 属性 class https://msdn.microsoft.com/en-us/library/bb187434(v=vs.85).aspx to tell your server to bind to the correct NIC. This is probably most easily done in the configuration. Does your server project have an app.config? If not add one then add a section like this to it (this is copy/pasted from this question .Net Remoting: Indicate which local interface to use to connect to one server)

<configuration>
    <system.runtime.remoting>
        <application>
            <channels>
                <channel ref="tcp" port="0" bindTo="172.xxx.xxx.xxx" />
            </channels>
        </application>
    </system.runtime.remoting>
</configuration>

这将告诉服务器绑定到特定的 IP 地址。

重新排序网络连接优先级对我的情况有所帮助。

http://ecross.mvps.org/howto/change-network-connection-priority-in-windows-10.htm

  1. 按 Windows 键 + X 和 select 菜单中的网络连接。
  2. 按 ALT 键,单击“高级”,然后单击“高级设置”。
  3. Select网络连接点击箭头优先网络连接

  1. 完成网络连接优先级的设置后,单击“确定”。当连接可用时,计算机现在将遵循命令。