遠程處理異常 - 身份驗證失敗的例外。詳細消息說:「無法從傳輸連接讀取數據:連接已關閉。」無法從傳輸連接讀取數據:連接已關閉
我在創建兩個可以在C#中作爲遠程對象進行通信的簡單服務器時遇到了問題。 ServerInfo只是我創建的一個擁有IP和端口的類,可以返回地址。它工作正常,就像我以前用過的那樣,並且已經調試過了。此外,服務器啓動正常,沒有任何異常,並且通道註冊沒有問題。我使用Forms來完成接口,並調用服務器上的某些方法,但在調試時從FormsApplication傳遞參數給服務器時沒有發現任何問題。在這一章中似乎都很好。
public ChordServerProgram()
{
RemotingServices.Marshal(this, "PADIBook");
nodeInt = 0;
}
public void startServer()
{
try
{
serverChannel = new TcpChannel(serverInfo.Port);
ChannelServices.RegisterChannel(serverChannel, true);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
我運行了這個程序的兩個實例。然後在應用程序的其中一個實例上調用startNode。端口很好,生成的地址也很好。正如你所看到的,我使用IP作爲本地主機,因爲這個服務器僅僅用於測試目的。
public void startNode(String portStr)
{
IPAddress address = IPAddress.Parse("127.0.0.1");
Int32 port = Int32.Parse(portStr);
serverInfo = new ServerInfo(address, port);
startServer();
//node = new ChordNode(serverInfo,this);
}
然後,在其他的方面,再次通過接口,我調用另一個startNode方法,給它一個種子服務器來獲取信息。這是它出錯的地方。當它調用剛剛獲得的seedServer代理上的方法時,由於驗證失敗,會拋出RemotingException。 (我想要得到的參數是節點,我只是用INT以確保ChordNode類無關,此錯誤。)
public void startNode(String portStr, String seedStr)
{
IPAddress address = IPAddress.Parse("127.0.0.1");
Int32 port = Int32.Parse(portStr);
serverInfo = new ServerInfo(address, port);
IPAddress addressSeed = IPAddress.Parse("127.0.0.1");
Int32 portSeed = Int32.Parse(seedStr);
ServerInfo seedInfo = new ServerInfo(addressSeed, portSeed);
startServer();
ChordServerProgram seedServer = (ChordServerProgram)Activator.GetObject(typeof(ChordServerProgram), seedInfo.GetFullAddress());
// node = new ChordNode(serverInfo,this);
int seedNode = seedServer.nodeInt;
// node.chordJoin(seedNode.self);
}
是的,但是如果我們想要啓用安全性呢? – Gareth 2012-01-11 16:04:42