【问题标题】:WCF Request Delay Every 50 SecondsWCF 请求延迟每 50 秒
【发布时间】:2017-01-05 13:45:16
【问题描述】:

我有一个简单的 WCF 服务,可以将图像流式传输到客户端。在客户端,第一个图像请求大约需要 5.5 秒,然后后续请求大约需要 40 毫秒,这很棒。

但是,每约 45 秒后,无论是否发出任何请求,下一个请求总是需要大约 4.6 秒。这个 45 秒的循环不断重复。

我正在使用带有流传输模式的 net.tcp 绑定。我也尝试过启用/不启用可靠会话的缓冲传输模式,但这只是增加了每个请求所花费的时间。

我已尝试增加每个绑定超时(打开、关闭、发送、接收、不活动),但没有任何变化。

服务器配置:

serviceHost = new ServiceHost(typeof(TServiceImplementation), serviceUri);
serviceHost.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = false });

var netTCPBinding = new NetTcpBinding(SecurityMode.Transport);
netTCPBinding.TransferMode = TransferMode.StreamedResponse;
netTCPBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;

serviceHost.AddServiceEndpoint(typeof(TServiceContract), netTCPBinding, ServiceName);
serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), "mex");

客户端配置:

<system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="TcpBinding" transferMode="StreamedResponse" maxReceivedMessageSize="2147483647" />
  </netTcpBinding>
</bindings>
<client>
  <endpoint address="net.tcp://hostname:9000/StreamService"
    binding="netTcpBinding" bindingConfiguration="TcpBinding" contract="StreamService.IStream"
    name="NetTcpBinding_IStream" />
</client>
</system.serviceModel>

更新:看起来这可能是特定于机器的问题 - 当我在本地机器上运行该服务时,我没有遇到此问题。

【问题讨论】:

  • 更改超时时间只会影响系统在声明错误之前等待响应的时间,它对您的响应速度没有影响,听起来您的应用程序池正在回收,这将删除您的服务并重新创建它需要几秒钟的正常运行时间,所以我会查看您的 IIS 设置
  • 它作为 Windows 服务运行,所以这可能不是问题。

标签: c# .net wcf wcf-configuration


【解决方案1】:

好的,所以进行更多调查,我确定这是一个地址解析问题 - 实际图像托管在与运行服务的机器不同的机器上,因此我将配置更改为使用主机的 IP 地址而不是计算机名称,问题就解决了。

我猜这与名称缓存超时有关,但尚未调查可能是哪一个。

【讨论】:

    猜你喜欢
    • 2014-12-04
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-14
    • 2022-01-20
    • 2019-02-13
    相关资源
    最近更新 更多