0

DTO オブジェクトを使用して WCF サービスからデータを転送します。

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 個のアイテムが返されたことはわかっています。返される一般的な情報は次のとおりです。

ここに画像の説明を入力

ご覧のとおり、返された各アイテムには多くのデータが含まれていません。しかし、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 個のアイテムに対して、これほど多くのデータを送信できるのはなぜですか??

4

1 に答える 1

2

MSDNから

Windows Communication Foundation (WCF) は、データ コントラクト シリアライザーと呼ばれるシリアル化エンジンを既定で使用して、データのシリアル化と逆シリアル化 (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 になります。

于 2012-05-05T19:09:11.370 に答える