繁体   English   中英

WCF与命名管道的双工通信

[英]Wcf duplex communication with named pipe

我们正在从.Net远程迁移到WCF。 如果可能的话,我们之前使用过IPC(因为我们考虑了性能)。

我试图复制使用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{...}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM