2014-01-27 159 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

相关问题