2

好吧,我不知道发生了什么。我在这里和谷歌搜索中找到了一堆帖子,但他们都说几乎相同的事情:更改客户端和服务器中的 maxStringContentLength。我已经这样做了,但我仍然遇到同样的错误。我也尝试过以编程方式更改最大长度,但没有骰子。

服务器上的 Web.config:

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


<behaviors>
  <endpointBehaviors>
    <behavior name="wsServiceBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483646" />
    </behavior>
  </endpointBehaviors>

  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

在客户端:

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

我还注意到,当我运行该服务时。生成的配置文件列出 maxStringContentLength = "8192"。我尝试关闭“启动服务时始终重新生成配置文件”选项并直接编辑配置文件以增加最大值,但它仍然不起作用。

--EDIT-- 看来该服务实际上并没有像 Eugune 提到的那样选择配置。我添加了:

    <services>
  <service name="Courrier.myService">
    <endpoint address="http://localhost:52826/Service1.svc" binding="basicHttpBinding"
      bindingConfiguration="BasicHttpBinding_IService1"
    contract="ServiceReference1.IService1">
    </endpoint>
  </service>
</services>

但仍然无法正常工作?

4

2 回答 2

3

当我在客户端看到这个错误时,通常意味着服务抛出了异常。如果您为 Web 服务打开了显示错误,则异常中的堆栈跟踪很容易突破 8192 字符串限制。

于 2012-10-05T19:08:47.750 回答
1

您确定您确实更改了服务器上的配额吗?在您的“服务器”配置中,您定义了一个具有增加配额的 BasicHttpBinding_IService1 绑定,但随后您只能在 <client> 部分中使用它。

于 2012-10-06T18:33:42.450 回答