How to send Protobufs across WCF method calls?

I have written and compiled some files .proto

using protobuf-csharp-port framework and I am trying to return it as a response to a WCF method call. Here's my service:

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

      

But it fails with the useless "server did not provide a meaningful response" error message.

The answers to another question suggested that it might be starting a blocker and not providing an error message, so I tried changing the contract to string

:

[OperationContract]
IEnumerable<string> GetLogItems();

      

and that works great, so it should be Protobuf related.

My presumption is that WCF cannot serialize Protobuf for some reason. I've seen a lot of people writing [DataContract]

, but this seems only relevant for protobuf-net

, but I couldn't find any information on protobuf-csharp-port

, which doesn't seem to be using in [DataContract]

exactly the same way. I tried to set the parameter -code_contracts

for Protogen to true

, but that 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 serialize Protobuf manually, but that would be tedious, so I want WCF to do it for me.

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

Edit # 1: I configured DataContractSerializer

manually and tried to serialize Protobuf. I am getting an error. 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.

It is clear that I cannot do this as the code is generated automatically. So: how, using ProtoGen or otherwise, add the appropriate attributes?

+3


source to share





All Articles