2012-05-05 59 views
0

我使用DTO對象從我的WCF服務傳輸數據。傳入郵件的最大郵件大小限額(400000)已被超出

這裏是DTO對象:

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

我知道我有我的服務返回的正是2116項。這裏是返回一個典型的信息:

enter image description here

正如你所看到的,是不是有很多在每個返回的項目的數據。但我不知道爲什麼我必須調整我的web.config綁定緩衝區以允許750000字節!

這裏是我的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> 

這裏是我的服務:

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

是否有人能解釋一下嗎?如果我將緩衝區從750000減少到400000,我得到錯誤:傳入消息的最大消息大小配額(400000)已被超出。要增加配額,請在適當的綁定元素上使用MaxReceivedMessageSize屬性。

我跟蹤WCF日誌文件,我發現從我的WCF傳輸的數據大約是721K。如何傳輸大約2116個小於20個字符的數據?

回答

2

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)

你的 「小」 對象看起來像這樣弄出來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.8 KB。

+0

+1。你可以嘗試一種替代編碼。對於標準的二進制編碼,最適合大小。請參閱http://msdn.microsoft.com/en-us/library/aa751889.aspx,或者如果您想付費購買,則Noemax FastInfoset更加緊湊。請參閱http://www.noemax.com/products/fastinfoset/size_comparisons.html –

相關問題