1

我有一个本地托管的 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

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

编辑

根据 Tim 的建议,这是我的新 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>

4

1 回答 1

1

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

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

如果您使用的是 .NET 4.0 并且没有指定服务元素,那么您使用的是默认端点和默认绑定(这意味着您的 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从客户端终结点中删除该属性。

于 2012-10-02T03:20:04.880 回答