繁体   English   中英

调用具有大量数据的Web服务时出错

[英]Error when calling web service with lots of data

我有一个本地托管的WCF服务。 我的web.config看起来像这样:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_INavigationService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="6553600" maxBufferPoolSize="5242880" maxReceivedMessageSize="6553600"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>      
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost/WebServices/NavigationService.svc/"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_INavigationService"
    contract="NavigationService.INavigationService" name="BasicHttpBinding_INavigationService" />
</client>   
</system.serviceModel>

如果我输入的文字少于8K,则我的服务正常。 还有更多,我得到以下错误:

Sys.WebForms.PageRequestManagerServerErrorException: The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'UpdateSiteMap'. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 75, position 166

有人可以告诉我如何增加文字配额吗? 如您所见,我将其设置为最大整数大小。

编辑

在蒂姆的建议之后,这是我的新Web.Config文件:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="6553600" maxBufferPoolSize="5242880" maxReceivedMessageSize="6553600"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>      
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost/WebServices/NavigationService.svc/"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_INavigationService"
    contract="NavigationService.INavigationService" name="BasicHttpBinding_INavigationService" />
</client>
<services>
  <service name="Navigation.INavigationService">

    <endpoint address="" 
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_INavigationService"
              contract="NavigationService.INavigationService"  />

  </service>
</services>

根据错误消息和对问题的描述,您需要确保对服务具有相同的设置,并在endpoint元素的bindingConfig属性中引用相同的定义绑定:

<system.serviceModel>
  <services>
    <service name="Navigation.INavigationService">
      <endpoint address="" 
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_INavigationService"
                contract="NavigationService.INavigationService" />
    </service>
  </services>
</system.serviceModel>

如果使用的是.NET 4.0,但未指定service元素,则使用的是默认终结点和默认绑定(这意味着maxStringContentLength的限制为8192)。 解决此问题的最简单方法是从配置的绑定部分中删除name属性-.NET随后将使用您的定义作为默认绑定。 例如:

<binding closeTimeout="00:01:00" ....

注意未设置name属性。

在这种情况下,您可能需要使用选项1,或者创建一个没有名称的类似绑定定义,因为我不能100%确定是否将默认绑定用于客户端。 他们绝对是为服务。

有关默认绑定和终结点的更多信息,请参见Windows Communication Foundation 4的开发人员简介

基于编辑的其他答案

尝试这个:

<client>
  <endpoint address="http://localhost/WebServices/NavigationService.svc/"
            binding="basicHttpBinding" 
            contract="NavigationService.INavigationService" 
            name="BasicHttpBinding_INavigationService" />
</client>

删除<services>部分,因为WCF 4.0的默认终结点机制将为您处理该问题,并从客户端终结点删除bindingConfiguration属性。

暂无
暂无

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

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