有没有办法使用NetNamedPipeBinding关闭双工模式(不支持IDuplexSessionChannel)

时间:2016-12-02 15:13:26

标签: c# wcf

我有一个简单的.NET(C#)应用程序,有三个线程:主线程和两个主线程产生的线程。第一个子项用于初始化并启动 ServiceHost 实例,使用 IFirstService 合同进行操作。第二种是使用 ChannelFactory 创建与 FirstService 线程进行通信的渠道的客户端。 NetNamedPipeBinding 用于此渠道。

执行

启动应用程序后
$(value)[0].appendChild(newElement); 

预期输出应为

mono application.exe

但实际结果是

Using System.ServiceModel.NetNamedPipeBinding...
FirstService Host is opened
Hello from Second Thread
FirstService Host is closed

的Program.cs:

Using System.ServiceModel.NetNamedPipeBinding...
FirstService Host is opened
NamedPipeChannelListener.OnAcceptChannel
NamedPipeChannelListener.OnAcceptChannel.2
NamedPipeChannelListener.OnAcceptChannel.3
NamedPipeChannelListener.OnAcceptChannel
System.InvalidOperationException: Channel type IDuplexSessionChannel is not supported.
at System.ServiceModel.MonoInternal.ClientRuntimeChannel..ctor (System.ServiceModel.Dispatcher.ClientRuntime runtime, System.ServiceModel.Description.ContractDescription contract, System.TimeSpan openTimeout, System.TimeSpan closeTimeout, System.ServiceModel.Channels.IChannel contextChannel, System.ServiceModel.Channels.IChannelFactory factory, System.ServiceModel.Channels.MessageVersion messageVersion, System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) [0x00165] in <8cdac92fdd4b495ba10570db10926ad4>:0
at System.ServiceModel.MonoInternal.ClientRuntimeChannel..ctor (System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.ChannelFactory channelFactory, System.ServiceModel.EndpointAddress remoteAddress, System.Uri via) [0x0002c] in <8cdac92fdd4b495ba10570db10926ad4>:0
at System.ServiceModel.ChannelFactory`1[TChannel].CreateChannel (System.ServiceModel.EndpointAddress address, System.Uri via) [0x0005b] in <8cdac92fdd4b495ba10570db10926ad4>:0
at System.ServiceModel.ChannelFactory`1[TChannel].CreateChannel (System.ServiceModel.EndpointAddress address) [0x00000] in <8cdac92fdd4b495ba10570db10926ad4>:0
at System.ServiceModel.ChannelFactory`1[TChannel].CreateChannel () [0x00012] in <8cdac92fdd4b495ba10570db10926ad4>:0
at WcfNamedPipeBindingTest.MainClass.SecondPointThread (System.Object binding_info) [0x00041] in <ef4f03ef8ba048f3b924916715fa960b>:0
FirstService Host is closed

我可以避免使用DuplexSessionChannel吗?

1 个答案:

答案 0 :(得分:0)

我认为使用命名管道进行WCF(使用MMF作为其实现的一部分)不适用于Mono。

但是,您可以将NetTcpBinding与Mono一起使用。尝试将绑定更改为以下内容:

var binding_info = new BindingInfo
{
    binding = new NetTcpBinding(),
    uri = new Uri("net.tcp://localhost/ftest")
};