2012-05-05 28 views
0

私のWCFサービスからDTOオブジェクトでデータを転送しています。ここで受信メッセージ(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

をあなたが見ることができるように、多くのデータが返される各項目にはありません。しかし、なぜ私は750000バイトを許可するために私のweb.configバインディングバッファを調整する必要があるのか​​わかりません!ここで

は私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であることを発見しました。 20文字未満の約2116項目について、それほど多くのデータを送信することは可能ですか?

答えて

2

それはDataContractSerializer出てきた後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)

から自分の "小さな" オブジェクトは、次のようになります。

<?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を参照してください。 –

関連する問題