2014-01-27 156 views
0

結果:您的確犯了一個愚蠢的錯誤。將我的客戶端錯誤地添加到服務的字典中導致錯誤。我在所有錯誤的地方尋找問題。WCF客戶端在重新啓動後無法重新連接

我有一個帶回調的命名管道WCF服務。它報告USB設備插入事件給客戶端。我遇到的問題是,如果我退出客戶端並重新啓動它,我總會遇到通道故障。當我退出客戶端我打電話的代碼如下:

 public void Dispose() 
     { 
      try 
      { 
       if (factory.State == CommunicationState.Opened) 
       { 
        proxy.UnSubscribe(_clientName); 
        factory.Close(); 
       } 
       else 
       { 
        factory.Abort(); 
       } 
      } 
      catch (Exception) 
      { 
       factory.Abort(); 
      } 
     } 

創建渠道如下:

  NetNamedPipeBinding netPipe = new NetNamedPipeBinding(); 
      // Security is not worth it for this. 
      netPipe.Security.Mode = NetNamedPipeSecurityMode.None; 
      // The receive time on the client side is ignored. The time the callback session 
      // is kept alive is determined by the receive time on the service side which is infinite. 
      factory = new DuplexChannelFactory<IUsbBroker>(
        new InstanceContext(this), netPipe, 
        new EndpointAddress("net.pipe://localhost/Gyannea/WCFCallbacks/UsbBroker")); 
      try 
      { 
       proxy = (IUsbBroker)factory.CreateChannel(); 
      } 
      catch (Exception) 
      { 
       factory.Abort(); 
      } 

我新添加在try-catch在通道/代理的創建,看看是否是當我重新啓動客戶端以嘗試重新嘗試重新創建通道時,如果在中止後發生故障,則會出現問題。它不起作用。

我在這裏錯過了什麼? 謝謝!

回答

0

你如何主辦wcf服務。

如果您在Windows Vista或更高版本上運行,則WCF net.pipe服務將僅對在相同登錄會話中運行的進程可訪問,否則您需要具有管理權限。您應該在Windows服務中託管您的服務

請參閱下面的帖子

Client on non-admin user can't communicate using net.pipe with services

Minimum OS Permissions required to create named pipe (WCF)

+0

我自託管的服務,並在管理模式下運行的可執行文件(它不會在連接所有在管理模式下運行)。同時,我可以使用同一客戶端的N個實例連接到服務。但是,當我退出客戶端#n並重新啓動它時,我無法連接。其餘的客戶仍然很好。客戶端不處於管理模式。客戶端是否需要進入管理模式?這是多個實例的問題?也許我沒有正確使用雙工通道(WCF對我來說是全新的!) –

+0

事實證明,我錯誤地將我的客戶端添加到了服務的字典中。愚蠢的錯誤使我耗費兩天的不停的頭髮拉動。 –

+0

很高興聽到你設法解決你的問題。這是博客文章討論wcf雙向通信與namepipe http://dotnet-experience.blogspot.com.au/2012/02/inter-process-duplex-communication-with.html – Mahesh

相關問題