2017-07-26 123 views
0

我们正在从.Net远程处理转移到WCF。如果可能,我们之前使用过IPC(因为我们有性能考虑)。Wcf与命名管道的双工通信

我试图复制我们使用WCF进行.Net远程处理的第一个“服务”。

在服务器上发生一些事件之前,必须将其转发给客户端。客户正在给出一个代理来通知这样的事件。

在WCF中,我的理解是我们必须使用DUPLEX通信,所以我在我的ServiceContract上指定了CallBackContract

但现在当我尝试使用它,我得到这么样的错误:

合同要求双面打印,但绑定“NetNamedPipeBinding”不 支持,或没有正确配置来支持它。

我做错了什么?或者我们真的不能有双向沟通(查询 - 响应除外)?我不能相信这是可能的.Net Remoting,但不是在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(); 

服务声明:

[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IMyServiceCallback))] 
//Note I also tried without the SessionMode specified 
    public interface IMyService: IService{...} 

服务实现:

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

使用回调取决于绑定。但是'NetNamedPipeBinding'支持双工,如[here](http://www.dotnettricks.com/learn/wcf/understanding-various-types-of-wcf-bindings)所示。所以我想这个问题必须来自你的配置。回调配置可能有点棘手。请向我们展示您的实施和双方的配置。 – Rabban

+0

@Rabban我从我们的实现中提取了一切,将其放在这里。我还注意到的一件事是,我有与会话模式相同的问题(说它不支持,而我看到一些互联网上的例子 – J4N

+0

一见钟情,它看起来类似于我们的双工配置。 MaxBufferPoolSize和MaxReceivedMessageSize等问题,你只能使用Int32.MaxValue而不是Int64,这可能是你的问题的根源请注意你的Client和Server配置应该是 – Rabban

回答

0

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