【问题标题】:WCF, NetTcpBinding, Streamed transfer mode can be duplex?WCF、NetTcpBinding、Streamed传输方式可以双工吗?
【发布时间】:2012-08-25 08:16:26
【问题描述】:

我将 NetTcpBinding 与 Streamed TransferMode 一起使用。现在我尝试将回调实现为双工,但收到错误消息。可以将 NetTcpBinding 与 Streamed TransferMode 一起使用并使用(双工)回调服务合同吗? 的背景: - 我使用 NetTcpBinding 因为它速度快而且没有 nat 问题 - 我使用流模式,因为我也传输大文件。

配置:

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

合同:

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

设置 transferMode="Streamed" 时出现错误

Contract 需要 Duplex,但绑定 'NetTcpBinding' 不支持 它或未正确配置以支持它。

每个人都可以建议谢谢

【问题讨论】:

  • 您是使用 DuplexChannelFactory 连接到服务器(还是仅使用 ChannelFactory)?
  • 我使用 IMetadataExchange 添加 servicereferece 并创建客户端代理

标签: c# .net wcf


【解决方案1】:

在您的客户端代码中,确保您使用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();
    }
}

[编辑] 自动生成的服务引用的代理应该扩展 DuplexClientBase

【讨论】:

  • 你误解了我的问题。我的问题是当我设置属性 transferMode="Streamed" 时当前服务器没有运行配置,如果是删除它服务器运行但我想使用大文件上传应该 transferMode="Streamed" 是好的选择
  • 是的,使用配置属性 transferMode="Streamed",默认设置 transferMode="Buffer" 但在我的情况下使用 dublex 会出现问题
  • This answer 提到了有序消息、回调和流媒体的一些问题。 (选择其中任何两个,它会起作用——不是同时三个)。启用流式传输后,双工通道将不起作用。对不起。
  • 可能的解决方法包括:使用两个单独的合约/通道(一个流式传输,一个不流式传输)和/或重构回调。
  • 您建议详细一点吗?这是一个很好的建议。
猜你喜欢
  • 1970-01-01
  • 2011-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-01
  • 1970-01-01
  • 2010-09-11
  • 1970-01-01
相关资源
最近更新 更多