[英]Hosting NamedPipe in WPF application does not create a pipe
I'm on .NET 3.5 I have two WPF projects which should communicate with each other both ways. 我在.NET 3.5上,我有两个WPF项目,应该以两种方式相互通信。 I figured that named pipes would do the job with WCF making it very easy with duplex mode. 我认为使用WCF可以完成命名管道的工作,从而使双工模式变得非常容易。 However, I start a WCF named pipe host in one application and can't see it in another app. 但是,我在一个应用程序中启动了一个名为WCF的管道主机,在另一个应用程序中看不到它。 Also 也
pipelist.exe | findstr "MainApplication"
Where MainApplication is the pipe name returns nothing (pipelist.exe is the utility from SysInternals). 其中MainApplication是管道名称,不返回任何内容(pipelist.exe是SysInternals的实用程序)。
I have the following app.config: 我有以下app.config:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="MainApplication" behaviorConfiguration="Default">
<endpoint address="" binding="netNamedPipeBinding" name="MainApplication" contract="IMainApplication" />
<endpoint address="mex" binding="mexNamedPipeBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/MainApplication" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>
And the code which should start the listener in Application: 以及应在Application中启动侦听器的代码:
protected override void OnStartup(StartupEventArgs e)
{
var serviceThread = new Thread(ServiceCommunications);
serviceThread.Start();
base.OnStartup(e);
}
private void ServiceCommunications()
{
var host = new ServiceHost(typeof(MainApplication));
host.Open();
}
What did I miss? 我错过了什么? I don't get any exception, however I can't find the pipe when I try to add service reference to my second project, neither I can list it with pipelist.exe Did I miss something basic? 我没有任何异常,但是当我尝试向第二个项目中添加服务引用时找不到管道,也无法通过pipelist.exe列出该管道。我错过了一些基本的东西吗?
I changed the ServiceCommunications method to 我将ServiceCommunications方法更改为
private void ServiceCommunications()
{
var host = new ServiceHost(typeof(MainApplication));
host.Open();
while (keepAlive)
{
// Do nothing
}
host.Close();
}
And it resolved the issue. 并且它解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.