2017-07-26 126 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不支持傳輸模式全雙工通信流。只需使用另一種運輸模式。