2014-03-06 51 views
2

我有一个Windows服务,它在同一台机器上产生一个子进程。他们通过TCP远程进行双向通信。子进程ping父进程没有问题,但从父进程的客户端到子进程的远程服务的ping调用永远不会返回。远程处理调用永不返回

日志显示子进程使用期望的端口和服务名称注册服务器通道。但是,我提供了127.0.0.1作为主机,但是在查看ChannelData中的uri值时,我看到机器的实际IP地址而不是回送地址。用这个实际的IP地址而不是127.0.0.1注册孩子的服务器通道并没有什么区别。

的Netstat表明预期的端口监听:

TCP 0.0.0.0:23167 pc-name:0 LISTENING hostingProcId 
TCP 0.0.0.0:23461 pc-name:0 LISTENING hostedProcId 

服务是WellKnownObjectMode.Singleton。我不知道以下信息是否重要,但为了以防万一,我不重写可编组对象的InitializeLifetimeService。

向cahnnel属性添加secure = false并没有这样做,也没有在相关端口上明确设置和禁止防火墙规则。

我同步跨进程以确保客户端在子进程完全建立之前不尝试激活远程对象。

任何想法?父

客户端安装:

public IpcCallResponseData PingHostedProcess(int processId) 
{ 
    return Service.Ping(new IpcCallRequestData(processId)); 
} 

Server安装上孩子:

:对孩子

protected RemotingTcpServer(IpcUniplexConfig config, TService service, WellKnownObjectMode objectMode) 
{ 
    Port = config.Port; 
    Service = service; 

    var props = new Hashtable(); 
    props["port"] = Port; 
    props["name"] = service.ServiceName; 

    Channel = new TcpServerChannel(props, null); 
    ChannelServices.RegisterChannel(Channel, true); 
    RemotingConfiguration.RegisterWellKnownServiceType(Service.GetType(), Service.ServiceName, objectMode); 
} 

服务父

protected RemotingTcpClient(IpcUniplexConfig config) 
{ 
    Host = config.Host; 
    Port = config.Port; 
    ServiceName = config.ServiceName; 

    var props = new Hashtable(); 
    props["name"] = ServiceName; 
    props["timeout"] = config.Timeout;   

    Channel = new TcpClientChannel(props, null); 
    ChannelServices.RegisterChannel(Channel, true); 

    var uri = string.Format("tcp://{0}:{1}/{2}", Host, Port, ServiceName);   
    Service = (TService)Activator.GetObject(typeof(TService), uri); 
} 

客户端

public IpcCallResponseData Ping(IpcCallRequestData data) 
{ 
    ... some processing ... 
    return new IpcCallResponseData(_processId); 
} 

回答

1

如果您需要双向通信,则客户端和服务器都需要同时注册客户端和服务器通道。如果你创建并注册在RemotingTcpServer一个TcpClientChannel,然后创建并在RemotingTcpClient,它可以工作在同一个端口上侦听注册TcpServerChannel

希望!

+0

我当然会这样做,双方都注册一个服务器和一个客户端。我只粘贴与有问题的方向有关的代码,以便不用无关代码搞乱我的问题 – Dondey

相关问题