2014-03-06 79 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

相關問題