[C#]Client呼叫WebService時發生逾時作業

這個實作是使用VS2010寫的, 微軟在VS2010已將原本的ASP.NET WebService整合至WCF, 所以相關資料用WCF去找比較找得到。

[Server端]

1. web.config (在<system.web></system.web>之間)

<httpRuntime executionTimeout="1000"/>, 單位為秒, 設定仍無效


<sessionState mode="InProc" timeout="200" cookieless="UseCookies"></sessionState>, 單位為分鐘, 設定仍無效


[Client端]

1.修改app.config
引用WebService後, app.config會增加下列的XML

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="WebService1Soap"/>
        <binding name="Service1Soap" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://127.0.0.1/ws/WebService1.asmx" binding="basicHttpBinding"
        bindingConfiguration="WebService1Soap" contract="rsService1.WebService1Soap"
        name="WebService1Soap" />
      <endpoint address="http://127.0.0.1/ws1/Service1.asmx" binding="basicHttpBinding"
        bindingConfiguration="Service1Soap" contract="rsService2.Service1Soap"
        name="Service1Soap" />
    </client>
  </system.serviceModel>

增加 receiveTimeout="00:10:00" sendTimeout="00:10:00" (表示10分鐘)

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="WebService1Soap" receiveTimeout="00:10:00" sendTimeout="00:10:00"/>
        <binding name="Service1Soap" receiveTimeout="00:10:00" sendTimeout="00:10:00"/>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://127.0.0.1/ws/WebService1.asmx" binding="basicHttpBinding"
        bindingConfiguration="WebService1Soap" contract="rsService1.WebService1Soap"
        name="WebService1Soap" />
      <endpoint address="http://127.0.0.1/ws1/Service1.asmx" binding="basicHttpBinding"
        bindingConfiguration="Service1Soap" contract="rsService2.Service1Soap"
        name="Service1Soap" />
    </client>
  </system.serviceModel>


2. coding (有效), 通常用在該程式需要設定較長的時間

rsService1.WebService1SoapClient aa = new rsService1.WebService1SoapClient();

aa.InnerChannel.OperationTimeout = new TimeSpan(0, 2, 0);    //可以設定Timeout

String str = aa.HelloWorld();

留言

這個網誌中的熱門文章

ORA-12514: TNS: 監聽器目前不知道連線描述區中要求的服務

Oracle 例外控制(Exception Control)

Oracle 工作排程 DBMS_JOB 筆記