2010-12-17 63 views
1

我使用客戶端和服務器之間的遠程處理,雖然它的工作原理,我看到一些我不明白的行爲。測試遠程代理是否有效?

我設置了我的服務器如下:

 BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider(); 
     serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;    
     BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider(); 

     IDictionary props = new Hashtable(); 
     props["name"] = "MarsLogServer.rem"; 
     props["port"] = Properties.Settings.Default.ListeningPort; 
     props["useIpAddress"] = false; 

     server = new LogServer(); 

     chan = new TcpChannel(props, clientProv, serverProv); 
     ChannelServices.RegisterChannel(chan, true);    
     RemotingConfiguration.RegisterWellKnownServiceType(typeof(LogServer), "MarsLogServer.rem", WellKnownObjectMode.Singleton);    

而我的客戶端連接如下:

this.logServer = (ILogServer)Activator.GetObject(typeof(ILogServer), connectForm.Url); 
this.logServer.AttachClient(this, connectForm.SessionKey) 

發生了什麼事是我甚至不具備的服務器上運行,但我在客戶端代理上對AttachClient()的調用成功。我不明白爲什麼會這樣,沒有進程在提供的URL上運行託管對象(除非有人在對我玩耍),那爲什麼它不拋出異常呢?

理想情況下,我希望通話失敗,或者我想要某種方式在允許我的客戶端繼續前測試我的代理是否有效。現在它無法知道連接是否成功。

回答

0

也許你可以使用System.Runtime.Remoting.RemotingServices.IsTransparentProxy(客戶端)來測試TransparentProxy/RealProxy鏈是否已設置?

-Oisin

+0

試過,它返回true。 – Joe 2010-12-17 18:51:41