简体   繁体   English

WCF请求每50秒延迟一次

[英]WCF Request Delay Every 50 Seconds

I have a simple WCF service that streams images to the client. 我有一个简单的WCF服务,可以将图像流式传输到客户端。 On the client, the first request for an image takes around 5.5 seconds and then subsequent requests take around 40ms, which is great. 在客户端上,对图像的第一次请求大约需要5.5秒,然后后续请求大约需要40ms,这很好。

However, after every ~45 seconds, regardless of whether any requests have been made the next request always takes around 4.6 seconds. 但是,每隔约45秒,无论是否有任何请求,下一个请求总是需要大约4.6秒。 This 45 second cycle repeats continuously. 这45秒的循环不断重复。

I am using net.tcp binding with streamed transfer mode. 我使用net.tcp绑定与流传输模式。 I have also tried buffered transfer mode with/without reliable sessions enabled but all this did was increase the time taken for each request. 我还尝试了启用/不启用可靠会话的缓冲传输模式,但所有这些都增加了每个请求所花费的时间。

I have tried increasing each of the binding timeouts (open, close, send, receive, inactivity) with no change. 我已经尝试增加每个绑定超时(打开,关闭,发送,接收,不活动)而不做任何更改。

Server config: 服务器配置:

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

Client config: 客户端配置:

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

UPDATE: It looks like this might be a machine specific issue - when I run the service on my local machine I do not experience this issue. 更新:看起来这可能是特定于机器的问题 - 当我在本地计算机上运行服务时,我没有遇到此问题。

Ok, so a bit more investigation and I have determined that this was an address resolution issue - The actual images were hosted on a different machine to the one running the service so I changed the config to use the IP address of the host rather than the computer name and the problem was resolved. 好的,所以多一点调查,我已经确定这是一个地址解析问题 - 实际的图像托管在运行服务的机器的不同机器上,所以我更改了配置以使用主机的IP地址而不是计算机名称和问题已解决。

I'm guessing this has something to do with a name cache timeout but not looked into which one it could be yet. 我猜这与名称缓存超时有关,但没有考虑它可能是哪一个。

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

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