问题
I am using protobuf-net with WCF, and finding that data members with Order = 0 are not showing up on the client. Here is my data contract - ObjectId is always Guid.Empty on the client side.
<DataContract()> _
Public Class ProtocolBufferDataContract
<DataMember(Order:=0)> _
Public Property ObjectId() As Guid
<DataMember(Order:=1)> _
Public Property Title() As String
End Class
I am using the shared-assembly mechanism, so both the server and client are compiled against this class. If I change the orders to 1 and 2, everything works. Why doesn't it work with 0?
回答1:
Odd - I would have expected it to error with that. Protobuf key numbers are always positive, so 0 is indeed not valid for protobuf-net. Hence I would expect it to throw! For this reason, it. Is also possible to specify an offset to apply to WCF keys (intended primarily for use with proxy types). This can be done via ProtoContractAttribute (directly, or in a "partial class" if using proxy generation), or can probably (I haven't checked) be applied at runtime via RuntimeTypeModel.
来源:https://stackoverflow.com/questions/10340381/does-protobuf-net-support-datamemberorder-0