1

以下は、protobuf-net バージョン 2.0.0.480 を実行する WCF 環境で機能するクラス定義と機能しないクラス定義です。

処理コードが応答のリストに実際の型 (この場合は SomeClassRow) を入力することを知っておいてください。

さらに奇妙なことに、SomeResponse の悪いバージョンでは、WCF が機能する場合と機能しない場合がありました。

これが、IDataRow インターフェイスを使用する理由です。これにより、応答のリストに任意のタイプの行を保持できます。

問題は、リストが強力な型とインターフェイス (IDataRow) で定義されている場合に、protobuf が逆シリアル化に失敗するのはなぜですか?

Thanks,
Ninos

[ProtoContract]
[ProtoInclude(101, typeof(BaseClassInfo))]
public interface IDataRow
{
}

[ProtoContract]
[ProtoInclude(101, typeof(SomeClassRow))]
public class BaseClassInfo : IDataRow
{
   [ProtoMember(1)]
   public int SomeId { get; set; }
   ...
}

// This version of the class won't work because it defines the collection with the
// strongly type name i.e. List<Some
[ProtoContract]
public class SomeResponse
{
   [ProtoMember(1)]
   public List<SomeClassRow> Rows { get; set; }

   ...
}

// SomeClassRow is in turn an IDataRow.
[ProtoContract]
public class SomeClassRow : BaseClassInfo
{
   [ProtoMember(1)]
   public string Name { get; set; }

   [ProtoMember(2)]
   public int Value { get; set; }

   ...  
}

// But, if the response is defined as follows then the WCF deserializes correcty and ALWAYS.
[ProtoContract]
public class SomeResponse
{
   [ProtoMember(1)]
   public List<IDataRow> Rows { get; set; }

   ...
}
4

0 に答える 0