2014-03-13 69 views
0

我使用Xamarin開發服務器客戶端應用程序。 我使用WCF從服務器發送數據到客戶端。 有時會發生超時異常。WCF over WSDL超時錯誤

我想這個服務器連接速度慢的問題。 通過快速的Wi-Fi,3G,4G是沒有問題的。但是如果連接速度小於3g,有時會發生超時。

我診斷使用Wireshark的連接,它說未來時超時(見圖片picture

請幫我解決這個問題。

回答

0

創建綁定時,您可以指定超時和讀取器配額。所以你必須提高超時跨度到一個合適的值。你可以通過代碼和配置文件來完成。

通過代碼,你可以做這樣的

var binding = new NetNamedPipeBinding() 
      { 
       OpenTimeout = TimeSpan.MaxValue, 
       CloseTimeout = TimeSpan.MaxValue, 
       SendTimeout = TimeSpan.MaxValue, 
       ReceiveTimeout = TimeSpan.MaxValue, 
       ReaderQuotas = { MaxStringContentLength = 2147483647, MaxBytesPerRead = 2147483647, MaxArrayLength = 2147483647 }, 
       MaxBufferSize = 6553500, 
       MaxReceivedMessageSize = 6553500 
      }; 

並通過配置文件,你可以做這樣的

<system.serviceModel> 
    <bindings> 
    <netTcpBinding> 
     <binding name="longTimeoutBinding" 
     receiveTimeout="00:10:00" sendTimeout="00:10:00"> 
     <security mode="None"/> 
     </binding> 
    </netTcpBinding> 
    </bindings> 

    <services> 
    <service name="longTimeoutService" 
     behaviorConfiguration="longTimeoutBehavior"> 
     <endpoint address="net.tcp://localhost/longtimeout/" 
     binding="netTcpBinding" bindingConfiguration="longTimeoutBinding" /> 
    </service> 
.... 
+0

我試圖做到這一點。但異常不會消失。 – user1737960

+0

@ user1737960你能顯示具體的異常嗎? – Redwan

+0

在這一行中我有例外:'code'((MobileServiceClient)_mobileService).InnerChannel.OperationTimeout = TimeSpan.FromMinutes(0.5); – user1737960