0

We are moving from .Net remoting to WCF. We were using IPC before(because we have performances consideration) when possible.

I tried to replicate the first "service" we were having on .Net remoting with WCF.

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.

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.

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?

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{...}
J4N
  • 19,480
  • 39
  • 187
  • 340
  • The use of Callbacks depends on the binding. But `NetNamedPipeBinding` supports duplex as shown [here](http://www.dotnettricks.com/learn/wcf/understanding-various-types-of-wcf-bindings). So i guess the issue must come from your configuration. Callback configuration can a little bit tricky. Please show us your implementation and the configs from both sides. – Rabban Jul 26 '17 at 09:33
  • @Rabban I extracted everything from our implementation to put it here. One thing I also noticed is that I've the same issue with the SessionMode(saying it's not supported while I see some example over the internet – J4N Jul 26 '17 at 10:59
  • On the first sight, it looks similar to our duplex configs. As i remember right, there was an issue with the `MaxBufferPoolSize` and `MaxReceivedMessageSize` and so on, that you can only use `Int32.MaxValue` and not `Int64`. This could be the root of your issue. Please note that your Client and Server config should be the same, or it could result in unpredictable behavior. – Rabban Jul 26 '17 at 11:46
  • @Rabban: I think I found the issue, I'm currently encountering other kind of issues, but it seems it doesn't like to have the `binding.TransferMode= TransferMode.Streamed;`. If I remove it I then have the error with the `Int64`, and now I've some other errors. – J4N Jul 26 '17 at 11:49

1 Answers1

0

WCF doesn't support duplex communication with transport mode streamed. Just use another transport mode.

Jeremy
  • 316
  • 3
  • 13