2011-08-26 106 views
0

我在作業中使用IPC來使服務程序與用戶程序進行通信。我不能讓用戶連接到服務程序IPC。IpcChannel連接問題

這裏是我的代碼:

服務器:

string name = application + "-" + cie + "-" + instance ; 
IDictionary properties = new Hashtable(); 
properties.Add("authorizedGroup", "Utilisateurs"); 
properties.Add("name", "CI.EventChannel"); 
properties.Add("portName", name); 
if (ChannelServices.GetChannel(name) != null) 
    ChannelServices.UnregisterChannel(ChannelServices.GetChannel(name)); 
channel = new IpcServerChannel(properties,null); 
ChannelServices.RegisterChannel(channel, true); 
//Register this service type. 
RemotingConfiguration.RegisterWellKnownServiceType(
         typeof(IpcServerMethodsEventGenerator), 
         "IpcServerMethodsEventGenerator", WellKnownObjectMode.Singleton); 

客戶:

IDictionary properties = new Hashtable(); 
properties.Add("authorizedGroup", "Utilisateurs"); 
properties.Add("name", "CI.EventChannel"); 
properties.Add("portName", ipc); //ipc values "EventGenerator-002-1" 
ipc = "ipc://" + ipc; 

//Create an IPC client channel. 
IpcClientChannel channel = new IpcClientChannel(properties,null); 

//Register the channel with ChannelServices. (channel, security) 
if (ChannelServices.GetChannel(channel.ChannelName) != null) 
    ChannelServices.UnregisterChannel(ChannelServices.GetChannel(channel.ChannelName)); 
ChannelServices.RegisterChannel(channel, true); 

//Register the client type. 
if (register) 
    RemotingConfiguration.RegisterWellKnownClientType(typeof(IpcServerMethodsEventGenerator), ipc); 

當我試圖用我的 「客戶端」 形式的連接,我得到一個連接錯誤,說明它找不到指定的文件。

謝謝你的幫助!

+0

我已經做了幾個錯誤。它正在工作。我顛倒了客戶端和服務器上的通道名稱和端口名稱,並且我在客戶端和服務器上都使用了相同的通道名稱,現在我知道這是錯誤的。 –

回答

0

它尋找一個遠程配置文件。在這裏尋找更多信息http://msdn.microsoft.com/en-us/library/ms973907.aspx

基本上你需要這樣的服務器

<configuration> 
    <system.runtime.remoting> 
    <application> 
     <service> 
     <activated type="Hello.AddService, Hello"/> 
     </service> 
    </application> 
    </system.runtime.remoting> 
</configuration> 

像這樣添加到客戶端

<configuration> 
    <system.runtime.remoting> 
    <application> 
     <client url="http://localhost:8000> 
     <activated type="Hello.AddService, Hello"/> 
     </client> 
    </application> 
    </system.runtime.remoting> 
</configuration> 
+0

他們可能無法溝通,因爲他們不是來自同一個項目? –

+0

如果他們在同一臺機器上,他們應該很容易溝通。當我的遠程配置文件無法找到時,我有無法找到遠程配置錯誤,我認爲這是你的錯誤是什麼?你可以添加我想要的全文 – kmcc049

+0

,但由於我的VS2005是法文的,我只能得到法文信息...... –