我在IIS 7.5及更高版本之上托管WCF服务使用protobuf-net绑定。
我与Guid类型属性签订了数据合同:
[Datacontract(Namespace = "http://lorem")]
public class MyCustomData {
[DataMember(Order = 0)]
public Guid Id { get; set; } // this ends up as empty, ie. 0000-0000-....
[DataMember(Order = 1)]
public int MyInt { get; set; } // serializes/deserializes ok
}
[ServiceContrac(Namespace = "http://ipsum"), Protobuf.ProtoContract]
public interface IMyService {
...
}
[ServiceBehavior(Namespace = "https://ipsum")]
public class MyService {
public void ServiceMethod(MyCustomData data) {
...
}
}
当呼叫到达服务时,问题是 MyCustomData.Id为空。
答案 0 :(得分:1)
解决:
问题是由protobuf-net的“功能”引起的
订单0被protobuf-net(Does protobuf-net support [DataMember(Order=0)]?)丢弃:
[Datacontract(Namespace = "http://lorem")]
public class MyCustomData {
[DataMember(Order = 0)]
public int Dummy { get; set; } // had to define, otherwise I get invalid wire-type exception
[DataMember(Order = 1)]
public Guid Id { get; set; } // now ok
[DataMember(Order = 2)]
public int MyInt { get; set; } // serializes/deserializes ok
}