I have a simple WCF service that streams images to the client. On the client, the first request for an image takes around 5.5 seconds and then subsequent requests take around 40ms, which is great.
However, after every ~45 seconds, regardless of whether any requests have been made the next request always takes around 4.6 seconds. This 45 second cycle repeats continuously.
I am using net.tcp binding with streamed transfer mode. 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.
I'm guessing this has something to do with a name cache timeout but not looked into which one it could be yet.