简体   繁体   English

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

[英]Consuming WCF with Delphi - Maximum string content length quota (8192) error

I have a WCF that is being consumed by a Delphi app. 我有一个由Delphi应用程序使用的WCF。 Sometimes I get this error when sending a large request to the server: 有时在向服务器发送大量请求时会出现此错误:

---------------------------
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   
---------------------------

I have configured the web.config on the server side as follow: 我在服务器端配置了web.config,如下所示:


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>

But I keep receiving this error. 但我一直收到这个错误。 Some people on Internet suggests that app.config on the client side should be modified as well, but I have no idea how to do that since I am using Delphi. Internet上的一些人建议客户端的app.config也应该修改,但我不知道怎么做,因为我使用的是Delphi。

I also noticed that I have no idea how to properly configure the <endpoint> tag, and maybe that is the cause of all my troubles. 我也注意到我不知道如何正确配置<endpoint>标签,也许这就是造成我所有麻烦的原因。 Bellow are both the interface and the class of my web service (reduced to be more clear): Bellow是我的Web服务的接口和类(简化为更清晰):


Interface: 接口:

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);
    }
}

Class

public class RoboConsultaLog : IRoboConsultaLog 
{
    ...
}

Does anyone knows how to fix this? 有谁知道如何解决这个问题?

As You noticed, it's beacuse of endpoint configuration: 正如您所注意到的,它是端点配置的结果:

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

Basically Your reader quota configuration wasn't used. 基本上没有使用您的读者配额配置。

Binding parameter defines type of binding only, if You want to pass a binding configuration You'll have to fill BindingConfiguration parameter. 绑定参数仅定义绑定类型,如果要传递绑定配置,则必须填写BindingConfiguration参数。 It's only a coincidence that binding type is the same as configuration name in Your case("basicHttpBinding"). 绑定类型与您的案例中的配置名称相同(“basicHttpBinding”)只是巧合。 So try this(I've changed name for clarity): 所以试试这个(我为了清晰起见改了名字):

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

and

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

EDIT: Additionally, if You send so much data, maybe It would be better to send it as a file, save it in Session and then use it in WCF method. 编辑:此外,如果您发送了这么多数据,也许最好将其作为文件发送,将其保存在Session中,然后在WCF方法中使用它。 Data would be send without WCF overhead, and WCF call would be a lot quicker, making application more responsive. 数据将在没有WCF开销的情况下发送,并且WCF调用会更快,使应用程序更具响应性。 Also it wouldn't be so prone to WCF timeouts. 它也不会那么容易出现WCF超时。

暂无
暂无

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

相关问题 WCF阅读器配额最大字符串内容长度配额(8192) - WCF reader quota The maximum string content length quota (8192) 将 XML 字符串发送到 WCF 时出现“读取 XML 数据时已超出最大字符串内容长度配额 (8192)”错误 - "The maximum string content length quota (8192) has been exceeded while reading XML data" error while sending XML string to WCF “在读取XML数据时已超出最大字符串内容长度配额(8192)”将XML字符串发送到WCF时出错 - “The maximum string content length quota (8192) has been exceeded while reading XML data” error while sending XML string to WCF WCF-读取XML数据时超出了最大字符串内容长度配额(8192) - WCF - The maximum string content length quota (8192) has been exceeded while reading XML data WCF Config修复最大字符串内容长度配额(8192) - WCF Config to fix The maximum string content length quota (8192) has been exceeded 反序列化类型的对象时发生错误...读取XML数据时超出了最大字符串内容长度配额(8192) - There was an error deserializing the object of type … The maximum string content length quota (8192) has been exceeded while reading XML data 已超过最大字符串内容长度配额(8192)。增加XmlDictionaryReaderQuotas的MaxStringContentLength属性 - The maximum string content length quota (8192) has been exceeded.Increase the MaxStringContentLength property on the XmlDictionaryReaderQuotas C#WCF最大字符串内容长度配额 - c# WCF maximum string content length quota 已处理ProtocolException,最大字符串内容长度配额8192 - ProtocolException was handled, Max string content length quota 8192 WCF Web服务无法反序列化,因为最大字符串内容长度配额 - WCF Web Service can't deserialize because of maximum string content length quota
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM