简体   繁体   English

WCF与命名管道的双工通信

[英]Wcf duplex communication with named pipe

We are moving from .Net remoting to WCF. 我们正在从.Net远程迁移到WCF。 We were using IPC before(because we have performances consideration) when possible. 如果可能的话,我们之前使用过IPC(因为我们考虑了性能)。

I tried to replicate the first "service" we were having on .Net remoting with WCF. 我试图复制使用WCF在.Net远程处理上获得的第一个“服务”。

Before we were having some events on the server that have to be forwarded to the client. 在服务器上发生一些事件之前,必须将这些事件转发给客户端。 The client was giving a proxy to inform of such event. 客户正在提供代理以通知此类事件。

In WCF, my understanding is that we have to use the DUPLEX communication, so I specified a CallBackContract on my ServiceContract . 在WCF中,我的理解是我们必须使用DUPLEX通信,因此我在ServiceContract上指定了CallBackContract

But now when I'm trying to use it, I get such kind of errors: 但是现在当我尝试使用它时,出现了这样的错误:

Contract requires Duplex, but Binding 'NetNamedPipeBinding' doesn't support it or isn't configured properly to support it. 合同要求使用双工,但是绑定'NetNamedPipeBinding'不支持它,或者没有正确配置为支持它。

Did I do something wrong? 我做错什么了吗? Or we really cannot have two way communication(other than query-response)? 还是我们真的不能进行双向通信(查询响应除外)? I cannot believe this was possible in .Net Remoting but not in WCF? 我不敢相信这在.Net Remoting中是可行的,但在WCF中却不可行?

EDIT 编辑

Here are my configurations 这是我的配置

Server side: 服务器端:

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);

Client side: 客户端:

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();

The service declaration: 服务声明:

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

The service implementation: 服务实现:

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

WCF doesn't support duplex communication with transport mode streamed. WCF不支持带有流传输模式的双工通信。 Just use another transport mode. 只需使用其他传输模式即可。

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

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