Question

Im hosting a WCF service on top of IIS 7.5 & using protobuf-net bindings.

I have a data contract with a Guid type property :


[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) {
    ...
  }
}

Issue is that MyCustomData.Id is empty when the call comes through to the service.

Was it helpful?

Solution

Solved:

Issue was caused by "feature" of protobuf-net

Order 0 is discarded by 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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top