【问题标题】:Consuming WCF with Delphi - Maximum string content length quota (8192) error使用 Delphi 使用 WCF - 最大字符串内容长度配额 (8192) 错误
【发布时间】:2012-08-07 18:04:36
【问题描述】:

我有一个被 Delphi 应用程序使用的 WCF。有时在向服务器发送大请求时会出现此错误:

---------------------------
Debugger Exception Notification
---------------------------
Project Project43.exe raised exception class ERemotableException with message 'The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'Log'. 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 58, position 140.'.
---------------------------
Break   Continue   Help   
---------------------------

我已经在服务器端配置了 web.config 如下:


Web.config

<?xml version="1.0" ?>
<configuration>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding">
          <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>

    <services>
      <service name="NewServiceType">
        <clear />
        <endpoint address="http://localhost" binding="basicHttpBinding" bindingConfiguration="" contract="IRoboConsultaLog" />
      </service>
    </services>

    <behaviors>
      <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>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

但我不断收到此错误消息。网上有人建议客户端的app.config也应该修改,但我不知道怎么做,因为我使用的是Delphi。

我还注意到我不知道如何正确配置&lt;endpoint&gt; 标签,也许这就是我所有麻烦的原因。下面是我的网络服务的接口和类(简化为更清晰):


界面:

namespace RoboConsultaLogServer
{
    [ServiceContract]
    public interface IRoboConsultaLog
    {
        [OperationContract]
        void Log(string key, string numeroSerial, string nomeTarefa, int qtdProcessos, float uptime, float duracaoTarefa,
                 int qtdSucesso, int qtdInsucesso, int qtdCancelado, bool servico, bool notificarResponsaveis, string logProcessos);
    }
}

public class RoboConsultaLog : IRoboConsultaLog 
{
    ...
}

有谁知道如何解决这个问题?

【问题讨论】:

    标签: c# wcf delphi soap web-config


    【解决方案1】:

    正如您所注意到的,这是因为端点配置:

    <endpoint address="http://localhost" binding="basicHttpBinding" bindingConfiguration="" contract="IRoboConsultaLog" />
    

    基本上没有使用您的阅读器配额配置。

    Binding 参数仅定义绑定类型,如果您想传递绑定配置,则必须填写 BindingConfiguration 参数。绑定类型与您的案例中的配置名称相同(“basicHttpBinding”)只是一个巧合。所以试试这个(为了清楚起见,我改了名字):

        <bindings>
          <basicHttpBinding>
            <binding name="myBindingConfiguration">
              <readerQuotas maxDepth="32" maxStringContentLength="5242880" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
          </basicHttpBinding>
        </bindings>
    

        <endpoint address="http://localhost" binding="basicHttpBinding" bindingConfiguration="myBindingConfiguration" contract="IRoboConsultaLog" />
    

    编辑:另外,如果您发送了这么多数据,也许最好将其作为文件发送,将其保存在 Session 中,然后在 WCF 方法中使用它。数据将在没有 WCF 开销的情况下发送,并且 WCF 调用会更快,从而使应用程序更具响应性。而且它不会那么容易出现 WCF 超时。

    【讨论】:

    • 现在我无法启动网络服务。它给了我这个错误:在服务“RoboConsultaLog”实施的合同列表中找不到合同名称“IRoboConsultaLog”
    • 向合约添加命名空间:contract="RoboConsultaLogServer.IRoboConsultaLog"
    • 错误标题为:配置中将'system.serviceModel/serviceHostingEnvironment/multipleSiteBindingsEnabled'设置为true时,需要endpoints指定相对地址。如果您在端点上指定相对侦听 URI,则地址可以是绝对地址。要解决此问题,请为端点“localhost”指定一个相对 uri。
    • 好的 .. 现在开始工作了。只需设置 。非常感谢!!!
    • 啊,我在比较我和你的配置,但没有注意到。其实我根本没有。嗯,我也刚刚学到了一些新东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-14
    相关资源
    最近更新 更多