简体   繁体   English

WCF,NetTcpBinding,流传输模式可以是双工吗?

[英]WCF, NetTcpBinding, Streamed transfer mode can be duplex?

I'm uses NetTcpBinding with Streamed TransferMode. 我将NetTcpBinding与Streamed TransferMode一起使用。 Now I tried to achieve a callback as duplex but I got error message. 现在,我尝试实现双工回调,但收到错误消息。 It is possible to use NetTcpBinding with Streamed TransferMode and use (duplex) callback service contract? 是否可以将NetTcpBinding与Streamed TransferMode一起使用,并使用(双工)回调服务协定? The background: - I use NetTcpBinding because it is fast and there's no nat issue - I use streamed mode because I tranfers big files as well. 背景:-我使用NetTcpBinding,因为它运行速度很快,而且没有问题。-我使用流传输模式,因为我也传输大文件。

the config: 配置:

 <netTcpBinding>
    <binding name="DuplexBinding" transferMode="Streamed"
                closeTimeout="00:10:00"  openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"  transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="104857600" maxReceivedMessageSize="104857600"
             >
      <readerQuotas maxDepth="104857600" maxStringContentLength="104857600" maxArrayLength="104857600" maxBytesPerRead="104857600" maxNameTableCharCount="104857600"/>
      <reliableSession enabled="true" ordered="true" inactivityTimeout="00:10:00"/>
      <security mode="None" />
    </binding>
  </netTcpBinding>

the contract: 合同:

IMyDataService.cs

   [ServiceContract(CallbackContract = typeof(INotifyCallback))]
    public interface IMyDataService
    {
        [OperationContract(ProtectionLevel = System.Net.Security.ProtectionLevel.None)]
        [FaultContract(typeof(MyFaultException))]
        [FaultContract(typeof(MyUserAlreadyLoggedInFaultException))]
        [FaultContract(typeof(AuthorizationFaultException))]
        Guid Authenticate(Guid clientID, string userName, string password, bool forceLogin);
    }


INotifyCallback.cs

    public interface INotifyCallback
    {
        [OperationContract(IsOneWay = true)]
        void ShowMessageBox(string message);
    }

i have get error whent set transferMode="Streamed" 设置transferMode =“ Streamed”时出现错误

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

everyone can suggest thanks 每个人都可以建议谢谢

In your client code, make sure you're using DuplexChannelFactory to create the channel to the server: 在客户端代码中,确保使用DuplexChannelFactory创建到服务器的通道:

INotifyCallback callbackObject = new NotifyCallbackImpl(); //your concrete callback class
var channelFactory = new DuplexChannelFactory<IMyDataServce>(callbackObject); //pick your favourite constructor!
IMyDataService channel = channelFactory.CreateChannel();
try {
    var guid = channel.Authenticate(....);
    //... use guid...
} finally {
    try {
        channel.Close();
    } catch (Exception) {
        channel.Abort();
    }
}

[Edit] The proxy of an auto-generated service reference should extend DuplexClientBase . [编辑]自动生成的服务引用的代理应扩展DuplexClientBase

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

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