簡體   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