2011-01-28 41 views
0

我有一個Windows服務,它包含一個WCF NetTcp主機。從客戶端,當我開始通過tcp調用服務時,他們首先通過罰款,但幾分鐘後,他們都開始提供可怕的WCF超時錯誤,這與超時確實無關:自託管的NetTcp服務超時錯誤

發送到net.tcp:// myserver:8080/ListingService的此請求操作未在配置的超時(00:01:00)內收到回覆。

我從本網站上的其他帖子看到,很多次這與最大消息大小有關,但我已經將這些限制設置爲無效。

這裏是我的窗口服務代碼:

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

你是否優雅地關閉了客戶端代理?這看起來像服務限制行爲。服務限制控制ServiceHost可以處理多少個併發呼叫,會話和實例。 NetTcp是面向會話的綁定 - 每個新的客戶端代理都會創建新的會話和服務實例,以處理來自同一個代理實例的所有請求。 – 2011-01-28 18:32:51

回答

0

他們結束了超時,因爲數據庫實際上超時,這不是一個問題與W CF.