简体   繁体   English

本地 WCF 服务上的 PipeException

[英]PipeException on local WCF service

I'm currently migrating a winforms app to WPF and the last thing I need to do is to migrate a WCF service我目前正在将一个 winforms 应用程序迁移到 WPF,我需要做的最后一件事是迁移 WCF 服务

Config file sender side:配置文件发送方:

<behaviors>
  <serviceBehaviors>
    <behavior name="NetPipeBehavior">
      <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="True" httpHelpPageEnabled="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service name="MyLibrary.WcfServiceController.GuiController" behaviorConfiguration="NetPipeBehavior">
    <endpoint address="" binding="netNamedPipeBinding" contract="MyLibrary.WcfServiceController.IGuiController" />
    <endpoint address="mex" binding="mexNamedPipeBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.pipe://localhost/GUI-ORG/" />
      </baseAddresses>
    </host>
  </service>
</services>

Client side:客户端:

<bindings>
  <netNamedPipeBinding>
    <binding name="NetNamedPipeBinding_IGuiController"/>
  </netNamedPipeBinding>
</bindings>
<client>
  <endpoint address="net.pipe://localhost/GUI-ORG/" binding="netNamedPipeBinding"
            bindingConfiguration="NetNamedPipeBinding_IGuiController"
            contract="GuiUpdaterReference.IGuiController" name="NetNamedPipeBinding_IGuiController">
  </endpoint>
</client>

I have a wrapper looking like this:我有一个看起来像这样的包装器:

public class GuiControllerClientWrapper
{
    private readonly LaunchType _launchType;
    private readonly GuiUpdaterReference.IGuiController _gc;

    public GuiControllerClientWrapper(LaunchType launchType)
    {
        _errorSent = false;
        _launchType = launchType;
        _gc = new GuiControllerClient();
        if (launchType == LaunchType.Manual)
        {
            ((GuiControllerClient)_gc).Open();
        }
    }

    /* other functions */
}

The exception occurs when calling Open(): EndpointNotFoundException: There was no endpoint listening at "net.pipe://localhost/GUI-ORG" that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.调用 Open() 时发生异常: EndpointNotFoundException: There was no endpoint listening at "net.pipe://localhost/GUI-ORG" that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. EndpointNotFoundException: There was no endpoint listening at "net.pipe://localhost/GUI-ORG" that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

InnerException is the following: The pipe endpoint 'net.pipe://localhost/GUI-ORG' could not be found on your local machine InnerException 如下: The pipe endpoint 'net.pipe://localhost/GUI-ORG' could not be found on your local machine

and then a stacktrace pointing to my wrapper calling the open function然后指向我的包装器的堆栈跟踪调用打开的 function

The thing is, if I add my old winforms GUI in the project and resintall everything, it does actually work, messages are sent and everything is normal问题是,如果我在项目中添加旧的 winforms GUI 并重新安装所有内容,它确实可以工作,发送消息并且一切正常

I have tried我努力了

  • using diagnostics, but it didn't give me any information I can work with使用诊断,但它没有给我任何我可以使用的信息
  • changing the address更改地址
  • recreating/updating the service reference重新创建/更新服务参考

What am I missing?我错过了什么?

Check if "Net.Pipe Listener Adapter" service is running in Services management console.检查“Net.Pipe Listener Adapter”服务是否在服务管理控制台中运行。

Start Windows service -> Net.Pipe Listener Adapter service 

No endpoint listening at net.pipe net.pipe 没有端点监听

Found the problem, and it wasn't WCF that at fault even if the exception could have helped me发现了问题,即使异常可以帮助我,也不是 WCF 有错

I have a service windows that runs everyday some code to check a local AD and do stuff I also have a GUI that allows me to control the service and start the processing manually我有一个服务 windows 每天运行一些代码来检查本地 AD 并做一些事情我还有一个 GUI 允许我控制服务并手动启动处理

When the button is clicked, an endpoint is started on the client (to have updates through a progressbar) but I didn't know that WPF rises an exception when a backgroundworker accesses the main thread (which wasn't the case in WinForms).单击该按钮时,会在客户端上启动一个端点(通过进度条进行更新),但我不知道 WPF 在后台工作人员访问主线程时引发异常(在 WinForms 中不是这种情况)。

My background worker would start, read the data source and then crash, going directly to the RunWorkerCompleted event that closes the endpoint我的后台工作人员将启动,读取数据源然后崩溃,直接进入关闭端点的RunWorkerCompleted事件

Here's where WCF could have helped me a bit more: when I started messing around with the background workers, the exception changed it was now telling me that the communication channel was closed prematurely这是 WCF 可以帮助我更多的地方:当我开始与后台工作人员相处时,异常发生了变化,现在它告诉我通信通道过早关闭

My code now uses a safe access to the UI thread, which make the channel stay alive as long as necessary我的代码现在使用对 UI 线程的安全访问,这使通道在必要时保持活动状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM