自托管NetTcp服务超时错误

时间:2011-01-28 18:05:33

标签: wcf timeout nettcpbinding servicehost

我有一个Windows服务,其中包含一个WCF NetTcp主机。从客户端开始,当我开始通过tcp调用服务时,它们首先处于罚款状态,但几分钟后它们都开始给出可怕的WCF超时错误,这与超时无关:

发送到net.tcp:// myserver:8080 / ListingService的请求操作未在配置的超时(00:01:00)内收到回复。

我从本网站的其他帖子中看到,很多时候这与最大邮件大小有关,但我已经将这些限制设置为无效。

这是我的Windows服务代码:

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

以下是客户端配置,以防它有任何区别:

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

我确保关闭我的客户端连接,这是代码:

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

1 个答案:

答案 0 :(得分:1)

他们最终超时,因为数据库实际上超时,这不是WCF的问题。