WCF over WSDL Timeout错误

时间:2014-03-13 06:39:38

标签: wcf xamarin wireshark

我使用Xamarin开发服务器 - 客户端应用程序。 我使用WCF从服务器向客户端发送数据。 有时会发生超时异常。

我猜这个与服务器连接速度慢的问题。 通过快速Wi-Fi,3g,4g没问题。但如果连接速度低于3g,有时会发生超时。

我诊断出与WireShark的连接,并在超时时说下一个(见图picture

请帮我解决这个问题。

1 个答案:

答案 0 :(得分: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>
....
相关问题