使用 WCF 与 Delphi 一起使用 - 最大字符串内容长度配额 (8192) 错误



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

---------------------------
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,如下所示:


网络.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。

我还注意到我不知道如何正确配置<endpoint>标签,也许这就是我所有麻烦的原因。波纹管是我的 Web 服务的接口和类(简化为更清晰):


接口:

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 
{
    ...
}

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

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

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

基本上,您的读取器配额配置未使用。

绑定参数

仅定义绑定类型,如果要传递绑定配置,则必须填写绑定配置参数。绑定类型与 Your case 中的配置名称相同("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" />

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

相关内容

最新更新