简体   繁体   English

批量查询Web服务返回“ Uri字符串太长”

[英]Batch query to webservice returns “The Uri string is too long”

I'm trying to send big request to server and get big data. 我正在尝试向服务器发送大请求并获取大数据。 So i use batch request to Data Service. 所以我使用批处理请求到数据服务。 URI of this request looks like this "hxxp://company/Test.svc/$batch". 此请求的URI看起来像这样的“ hxxp://company/Test.svc/$batch”。 I'm using .Net 4.0 我正在使用.Net 4.0

I send valid POST request: 我发送有效的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); }
        }
    }
}

And recieve an error message: 并收到一条错误消息:

<?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)&#xD;
   at System.Uri..ctor(String uriString, UriKind uriKind)&#xD;
   at System.Data.Services.RequestUriProcessor.GetAbsoluteUriFromReference(String reference, Uri absoluteServiceUri)&#xD;
   at System.Data.Services.BatchServiceHost..ctor(Uri absoluteServiceUri, BatchStream batchStream, String contentId, String boundary, StreamWriter writer)&#xD;
   at System.Data.Services.DataService`1.BatchDataService.CreateOperationContextFromBatchStream(Uri absoluteServiceUri, BatchStream batchStream, HashSet`1 contentIds, String boundary, StreamWriter writer)&#xD;
   at System.Data.Services.DataService`1.BatchDataService.HandleBatchContent(Stream responseStream)</stacktrace>
  </innererror>
</error>

It seems like server side exception, occures when it try to parse big uri. 尝试解析大uri时,似乎发生服务器端异常。 How to avoid this limitation? 如何避免这种局限性?

MODIFIED (28/01/2013 at 16:00) 修改(28/01 / 2013,16:00)

IIS configuration: 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>

If you are using IIS, I believe you can increase the max URL size by going to Request Filtering > Edit Feature Settings > Maximum URL Length. 如果您使用的是IIS,我相信您可以通过转到请求过滤>编辑功能设置>最大URL长度来增加最大URL大小。

The following guide should help you out further: http://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits 以下指南应进一步帮助您: http : //www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM