摘自: http://blog.csdn.net/gulijiang2008/article/details/4482993
請在服務器端配置
方法一:
在通過WebService處理大數據量數據時出現如下錯誤:
System.Web.Services.Protocols.SoapException: 在運行配置文件中指定的擴展時出現異常。 ---> System.Web.HttpException: 超過了最大請求長度。
at System.Web.HttpRequest.GetEntireRawContent()
at System.Web.HttpRequest.get_InputStream()
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
--- 內部異常堆棧跟蹤的結尾 ---
at System.Web.Services.Protocols.SoapServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
解決方法:是因為傳入的參數大於系統默認配置的值,asp.net web service默認的請求長度是4M。修改配置可以在web.config中重新設置,如下:
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
</system.web>
</configuration>
方法二:
<system.web>
<!-- 指示 ASP.NET 支持的最大文件上載大小。
該限制可用於防止因用戶將大量文件傳遞到該服務器而導致的拒絕服務攻擊。
指定的大小以 KB 為單位。默認值為 4096 KB (4 MB)。
此處改為40M大小的文件上傳限制。
-->
<httpRuntime maxRequestLength = "40960" useFullyQualifiedRedirectUrl="true"/>
</system.web>
-------------------------------------------------------------------------------------------
超時問題解決
-
首先修改服務端配置
WebService服務所在站點為服務端,它提供了服務,打開這個站點的web.config,添加下面的配置:
<httpRuntime executionTimeout="300000" />
<compilation defaultLanguage="c#" debug="false">
executionTimeout="300000" 單位是“毫秒”,這里配置的是5分鍾。
debug="false" 要關閉調試。
如果web.config中本來就有這兩個配置,修改一下就行了。如果沒有,就添加上去,完整的結構順序如下:
<configuration>
<system.web>
<httpRuntime executionTimeout="300000" />
<compilation defaultLanguage="c#" debug="false">
</compilation>
</system.web>
</configuration>
-
修改調用程序客戶端的配置
YourService. YourService model = new YourService. YourService ();
model.Timeout = 300000; // 單位是毫秒,設置時間,否則時間超限
這里給服務對象model設置超時時間Timeout為300000毫秒。
