3

I've written and compiled some .proto files using the protobuf-csharp-port runtime, and I'm trying to return one as the response to a WCF method call. Here's my service:

[ServiceContract]
public interface IService
{
    [OperationContract]
    IEnumerable<Protobuf.LogEntry> GetLogItems();
}

But this fails with an unhelpful "the server did not provide a meaningful reply" error message.

Answers to another question have suggested that this might be the serializer bombing out and not providing an error message, so I tried changing the contract to a string:

[OperationContract]
IEnumerable<string> GetLogItems();

and this works fine, so it must be something to do with the Protobuf.

My presumption is that WCF is not able to serialize the Protobuf for some reason. I've seen lots of people writing [DataContract] but this seems only relevant for protobuf-net, but I not could find any info about protobuf-csharp-port, which doesn't seem to use [DataContract] in quite the same way. I have tried setting the -code_contracts option for Protogen to true but this doesn't fix anything (it might not even be relevant).

So: how can I return a Protobuf object from a WCF method call? Obviously I could de/serialize the Protobufs manually, but this would get tedious so I want WCF to do it for me.

Note that I am not trying to replace WCF serialization with Protobuf; I just want to return a Protobuf object from a WCF method call.

Edit #1: I've set up a DataContractSerializer manually and tried to serialize a Protobuf. I get an error which says Type 'Protobuf.LogEntry' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMember attribute. Clearly, I cannot do this as the code is being generated automatically. So: how, using ProtoGen or otherwise, add appropriate attributes?

simonwo
  • 3,171
  • 2
  • 19
  • 28
  • Maybe you can write your own Message Encoder: http://blogs.msdn.com/b/carlosfigueira/archive/2011/11/09/wcf-extensibility-message-encoders.aspx. – Thomas Lielacher Jul 24 '15 at 10:23
  • Not an answer, but you probably should use protobuf-net because it is the canonical choice. – usr Jul 24 '15 at 10:33
  • @usr: Would protobuf-net allow me to generate Protobufs from .proto files with the necessary machinery to be sent through WCF? – simonwo Jul 24 '15 at 13:13
  • I thought you had said in the question that the problem would disappear with protobuf-net. – usr Jul 24 '15 at 13:22

0 Answers0