与命名管道的Wcf双工通信

问题描述 投票:0回答:1

我们正在从.Net远程处理转移到WCF。我们之前使用过IPC(因为我们有性能考虑)。

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

在我们在服务器上有一些必须转发到客户端的事件之前。客户端正在提供代理以告知此类事件。

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

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

合同需要Duplex,但Binding'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{...}
c# wcf named-pipes
1个回答
0
投票

WCF不支持流传输模式的双工通信。只需使用其他传输模式。

© www.soinside.com 2019 - 2024. All rights reserved.