[英]Batch query to webservice returns “The Uri string is too long”
我正在嘗試向服務器發送大請求並獲取大數據。 所以我使用批處理請求到數據服務。 此請求的URI看起來像這樣的“ hxxp://company/Test.svc/$batch”。 我正在使用.Net 4.0
我發送有效的POST請求:
DataServiceRequest[] Request = new DataServiceRequest[]{new DataServiceRequest<TTable>((query).RequestUri)};
try
{
DataServiceResponse dsr = WebService.ExecuteBatch(Request);
foreach (QueryOperationResponse qr in dsr)
{
if (qr.Query.ElementType == typeof(TTable))
{
foreach (TTable item in qr) { list.Add(item); }
}
}
}
並收到一條錯誤消息:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code></code>
<message xml:lang="ru-RU">An error occurred while processing this request.</message>
<innererror>
<message>Invalid URI: The Uri string is too long.</message>
<type>System.UriFormatException</type>
<stacktrace> at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at System.Data.Services.RequestUriProcessor.GetAbsoluteUriFromReference(String reference, Uri absoluteServiceUri)
at System.Data.Services.BatchServiceHost..ctor(Uri absoluteServiceUri, BatchStream batchStream, String contentId, String boundary, StreamWriter writer)
at System.Data.Services.DataService`1.BatchDataService.CreateOperationContextFromBatchStream(Uri absoluteServiceUri, BatchStream batchStream, HashSet`1 contentIds, String boundary, StreamWriter writer)
at System.Data.Services.DataService`1.BatchDataService.HandleBatchContent(Stream responseStream)</stacktrace>
</innererror>
</error>
嘗試解析大uri時,似乎發生服務器端異常。 如何避免這種局限性?
修改(28/01 / 2013,16:00)
IIS配置:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="500000000" maxQueryString="209715000" maxUrl="2000000"></requestLimits>
</requestFiltering>
</security>
<directoryBrowse enabled="true"/>
<httpErrors errorMode="Detailed"/>
<caching enabled="false" enableKernelCache="false"/>
</system.webServer>
<system.web>
<httpRuntime executionTimeout="4800"
maxQueryStringLength="2097150"
maxUrlLength="2097150"
relaxedUrlToFileSystemMapping="true"
maxRequestLength="500000000"
requestValidationMode="4.0"/>
<customErrors mode="Off"/>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Services.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
</system.web>
</configuration>
如果您使用的是IIS,我相信您可以通過轉到請求過濾>編輯功能設置>最大URL長度來增加最大URL大小。
以下指南應進一步幫助您: http : //www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.