Search code examples
restwcfprotobuf-net

WCF Rest service and protobuf-net


I followed this link.

[https://www.drdobbs.com/windows/working-with-protobuf-wcf-services/240159282][1]

This link basically shows how to use protobuf-net with WCF service for serialization. My requirement is to use WCF rest with WebGet and WebInvoke options. It doesn't work with this and I always get data at client side in xml serialization and not protobuf. I then went to countless links on here and other sites which claims working WCF + Protobuf but without WCF rest.

There was an information about developing own mediaformator for protobuf but the interface was in WCF preview (2011) and never made it to .net 4.6 I am using.

Am I missing something obvious here or protobuf will simply doesn't work with WCF rest?

Thanks Jay


Solution

  • So based on this answer here WCF protobuf endpoint 400 bad request, I could make Protobuf-net working but with a separate endpoint. It also has an issue with uri template for parameters. And also content negotiation is not possible this way as I can't change response type based on the client's accept header. After that I had a look at https://github.com/protobuf-net/protobuf-net/blob/main/src/protobuf-net/ServiceModel/ProtoEndpointBehavior.cs and can see that it also swaps the default datacontract serializer with proto one. Looks like multiple serializer cannot exist on the same endpoint for content negotiation this way.