2012-05-05 4 views
0

DTO 개체로 내 WCF 서비스에서 데이터를 전송합니다. 나는 내 서비스에서 반환 정확히 2116 항목이 알고들어오는 메시지 (400000)의 최대 메시지 크기 할당량이 초과되었습니다.

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

:

다음은 DTO 객체입니다. 여기에 반환 전형적인 정보는 다음과 같습니다

enter image description here

당신이 볼 수 있듯이, 각 반환 항목에서 많은 양의 데이터가 없습니다. 하지만 왜 내가 750000 바이트 허용하도록 내 web.config 바인딩 버퍼를 조정해야하는지 모르겠다!

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

내 서비스는 다음과 같습니다 :

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

누군가가 나를 설명 할 수 있는가 여기

내 web.condfig입니까? 버퍼를 750000에서 400000으로 줄이면 오류가 발생합니다. 들어오는 메시지 (400000)의 최대 메시지 크기 할당량이 초과되었습니다. 할당량을 늘리려면 해당 바인딩 요소에서 MaxReceivedMessageSize 속성을 사용합니다.

나는 WCF 로그 파일을 추적하고 내 WCF에서 전송 된 데이터가 약 721K임을 발견했습니다. 20 문자 미만의 약 2116 개 항목에 대해 너무 많은 데이터를 전송하는 것이 어떻게 가능합니까 ??

답변

2

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)

MSDN에서는 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> 

이 344 바이트입니다. 2116 개체의 경우 2116 * 344 = 727904 바이트 (710.8KB)입니다.

+0

+1. 대체 인코딩을 시도 할 수 있습니다. 표준형을 사용하면 바이너리 인코딩이 크기에 가장 적합합니다. http://msdn.microsoft.com/en-us/library/aa751889.aspx를 참조하십시오. 또는 Noemax FastInfoset를 지불하는 것이 좋습니다. http://www.noemax.com/products/fastinfoset/size_comparisons.html을 참조하십시오. –

관련 문제