C# Wcf与命名管道的双工通信

C# Wcf与命名管道的双工通信,c#,wcf,named-pipes,C#,Wcf,Named Pipes,我们正在从.Net远程处理转移到WCF。在可能的情况下,我们以前使用过IPC(因为我们考虑了性能) 我试图用WCF复制我们在.Net远程处理上的第一个“服务” 在服务器上有一些必须转发到客户端的事件之前。客户委托代理人告知此类事件 在WCF中,我的理解是我们必须使用双工通信,因此我在我的ServiceContract上指定了CallBackContract 但现在当我尝试使用它时,我会遇到这样的错误: 协定需要双工,但绑定“NetNamedPipeBinding”不需要 支持它或未正确配置以支持

我们正在从.Net远程处理转移到WCF。在可能的情况下,我们以前使用过IPC(因为我们考虑了性能)

我试图用WCF复制我们在.Net远程处理上的第一个“服务”

在服务器上有一些必须转发到客户端的事件之前。客户委托代理人告知此类事件

在WCF中,我的理解是我们必须使用双工通信,因此我在我的
ServiceContract
上指定了
CallBackContract

但现在当我尝试使用它时,我会遇到这样的错误:

协定需要双工,但绑定“NetNamedPipeBinding”不需要 支持它或未正确配置以支持它

我做错什么了吗?或者我们真的不能进行双向沟通(除了查询响应)?我不敢相信这在.Net远程处理中是可能的,但在WCF中却不可能

编辑

这是我的配置

服务器端:

Uri uri = new Uri("net.pipe://localhost/My/Service");
ServiceHost serviceHost = new ServiceHost(typeof(MyService),uri);

NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
binding.TransferMode= TransferMode.Streamed;
binding.Security.Transport.ProtectionLevel = ProtectionLevel.None;
binding.MaxBufferPoolSize = Int64.MaxValue;
binding.MaxBufferSize=Int32.MaxValue;
binding.MaxReceivedMessageSize=Int64.MaxValue;

ServiceEndpoint serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IMyService)), binding, uri);
serviceEndpoint.EndpointBehaviors.Add(new ProtoEndpointBehavior());

serviceHost.AddServiceEndpoint(serviceEndpoint);
客户端:

Uri uri = new Uri("net.pipe://localhost/My/Service");
EndpointAddress address = new EndpointAddress(uri);
InstanceContext context = new InstanceContext(callBack);
m_channelFactory = new DuplexChannelFactory<IMyService>(context, binding, endpoint);
m_channelFactory.Endpoint.EndpointBehaviors.Add(new ProtoEndpointBehavior());
m_channelFactory.Faulted += OnChannelFactoryFaulted;
m_innerChannel = m_channelFactory.CreateChannel();
服务实现:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] 
    public class MyService: IMyService, IDisposable{...}

WCF不支持传输模式为流的双工通信。只需使用另一种传输模式。

回调的使用取决于绑定。但
NetNamedPipeBinding
支持双工,如图所示。所以我想问题一定来自于你的配置。回调配置可能有点棘手。请向我们展示您的实现和双方的配置。@Rabban我从我们的实现中提取了所有内容,将其放在这里。我还注意到,我对SessionMode也有同样的问题(说它不受支持,但我第一眼看到Internet上的一些示例,它看起来类似于我们的双工配置。我记得很清楚,
MaxBufferPoolSize
MaxReceivedMessageSize
等存在问题,您只能使用
Int32.MaxValue
而不能使用
Int64
。这可能是错误的。)是问题的根源。请注意,您的客户端和服务器配置应该相同,否则可能会导致不可预测的行为。@Rabban:我想我找到了问题,我目前遇到了其他类型的问题,但似乎不希望绑定
绑定。TransferMode=TransferMode.Streamed;
。如果我删除它,我就有了用
Int64
检查错误,现在我还有一些其他错误。
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] 
    public class MyService: IMyService, IDisposable{...}