Bronzato
Bronzato

Reputation: 9362

The maximum message size quota for incoming messages (400000) has been exceeded

I transfer data from my WCF service with a DTO object.

Here is the DTO object:

[DataContract]
public class MatrixDTO : BaseDTO<MatrixDTO, Matrix>
{
    [DataMember]
    public int MatrixID { get; set; }

    [DataMember]
    public int OriginStopID { get; set; }

    [DataMember]
    public string OriginStopCode { get; set; }

    [DataMember]
    public int DestinationStopID { get; set; }

    [DataMember]
    public string DestinationStopCode { get; set; }

    [DataMember]
    public int NumberOfDays { get; set; }
}

I know I have exactly 2116 items returned by my service. Here is a typical info returned:

enter image description here

As you can see, there is not a lot of data in each returned item. But I don't know why I have to adjust my web.config binding buffer to allow 750000 bytes!

Here is my web.condfig:

      <binding name="WSHttpBinding_IRequestService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="750000" maxReceivedMessageSize="750000" messageEncoding="Text"
      textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
          algorithmSuite="Default" />
      </security>
    </binding>

Here is my service:

    public List<MatrixDTO> GetMatrices()
    {
        using (var unitOfWork = UnitOfWorkFactory.Create())
        {
            var matrixRepository = unitOfWork.Create<Matrix>();                
            var matrices = matrixRepository.GetAll();

            var dto = new List<MatrixDTO>();
            AutoMapper.Mapper.Map(matrices, dto);
            return dto;
        }            
    }

Does someone can explain me? If I reduce my buffer from 750000 to 400000 I got the error: The maximum message size quota for incoming messages (400000) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

I trace WCF log file and I discovered that data transmitted from my WCF is about 721K. How is it possible to have so much data transmitted for about 2116 items of less than 20 characters??

Upvotes: 0

Views: 965

Answers (1)

nemesv
nemesv

Reputation: 139808

From MSDN

Windows Communication Foundation (WCF) uses a serialization engine called the Data Contract Serializer by default to serialize and deserialize data (convert it to and from XML)

Your "small" object looks like this after it comes out the DataContractSerializer:

<?xml version="1.0" encoding="utf-8"?>
<MatrixDTO xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/SORepros.Tests">
    <DestinationStopCode>A-ANT</DestinationStopCode>
    <DestinationStopID>3</DestinationStopID>
    <MatrixID>3</MatrixID>
    <NumberOfDays>0</NumberOfDays>
    <OriginStopCode>PAO</OriginStopCode>
    <OriginStopID>1</OriginStopID>
</MatrixDTO>

This is 344 bytes. If you have 2116 object it's 2116 * 344 = 727904 bytes which is 710.8 KB.

Upvotes: 2

Related Questions