I have a windows service which houses a WCF NetTcp host. From the client, when I start making calls to the service via tcp, they go through fine at first but then after a few minutes they all start to give the dreaded WCF timeout error which really has nothing to do with timeouts:
This request operation sent to net.tcp://myserver:8080/ListingService did not receive a reply within the configured timeout (00:01:00).
I've seen from other posts on this site that a lot of times this has to do with the max message sizes, but I've already set these to the limits to no avail.
Here is my windows service code:
public partial class Service : ServiceBase
{
internal static ServiceHost myHost = null;
public Service()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
System.Net.ServicePointManager.DefaultConnectionLimit = 10000;
//create host.
var path = ConfigurationManager.AppSettings["ServiceHostAddress"].ToString();
myHost = new ServiceHost(typeof(ListingService));
//add endpoint.
myHost.AddServiceEndpoint(typeof(IListingService), GetBinding(), path);
//add behaviors.
AddBehaviors();
//open host.
myHost.Open();
}
private void AddBehaviors()
{
//service metadata behavior.
var smb = new ServiceMetadataBehavior();
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
myHost.Description.Behaviors.Add(smb);
//service throttling behavior.
var behavior = new ServiceThrottlingBehavior()
{
MaxConcurrentCalls = 10000,
MaxConcurrentInstances = 10000,
MaxConcurrentSessions = 10000
};
myHost.Description.Behaviors.Add(behavior);
//service debug behavior.
var serviceDebugBehavior = myHost.Description.Behaviors.Find<ServiceDebugBehavior>();
serviceDebugBehavior.IncludeExceptionDetailInFaults = true;
}
private Binding GetBinding()
{
var queueBinding = new NetTcpBinding(SecurityMode.None);
queueBinding.MaxConnections = 10000;
queueBinding.MaxBufferSize = 2048000;
queueBinding.MaxReceivedMessageSize = 2048000;
return queueBinding;
}
protected override void OnStop()
{
if (myHost != null)
{
myHost.Close();
myHost = null;
}
}
}
Here is the client config in case it makes any difference:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding" transferMode="Buffered" hostNameComparisonMode="StrongWildcard"
closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"><!-- transactionFlow="true"-->
<security mode="None"/>
<reliableSession enabled="false"/>
<readerQuotas maxArrayLength="2147483647"/>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint
address="net.tcp://myserver:8080/ListingService"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding"
contract="ListingServiceProxy.IListingService" name="NetTcpBinding" />
</client>
</system.serviceModel>
I make sure to close my client connections, here is the code:开发者_运维知识库
public static void Using<T>(this T client, Action<T> work)
where T : ICommunicationObject
{
try
{
work(client);
client.Close();
}
catch (CommunicationException)
{
client.Abort();
throw;
}
catch (TimeoutException)
{
client.Abort();
throw;
}
catch
{
client.Abort();
throw;
}
}
new ListingServiceClient().Using(client =>
{
client.SaveListing(listing);
});
They ended up timing out because the database was actually timing out, it wasn't an issue with WCF.
精彩评论