views:

299

answers:

2

I'm developing a web-service using WCF, which I want to access using a client written in Java. I will encode the messages using Protocol Buffers (with Marc Gravell's protobuf-net to be exact).

Is this possible to achive or must the client be written in .NET as well? I know that data serialized with Protocol Buffers is binary interopable but I don't know if WCF adds any platform-specific meta-data on top of the encoded protocol-messages.

I don't care if the WCF-service is RESTful, SOAP-based or whatever other forms WCF-support, I just want the actual payload to be encoded using PB. Is this possible and if it is, I would very much appreciate a brief example.

A: 

I have never used protobuf-net but interop was the whole point.

platform independent - portable between different programming architectures

Maurice
+1  A: 

If you program your WCF service to take a byte array, you can stuff whatever you want in there, like a protobuf message.Could be as simple as

  [ServiceContract]
    public interface IMessageService{
        [OperationContract(IsOneWay = true)]
        void SendMessage(byte[] msg);
    }

  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
   public class MessageService: IMessageService{

        public void SendMessage(byte[] msg) {
          //decode the protobuf msg and deal with it.
        }

    }

Configure the WCF endpoint as SOAP, then talking to that from Java should be straight foreward. Wether WCF/Soap would be overkill for this is another matter, iirc protobuf comes with its own framework for simple RPC.

nos
Thanks, that's an option. I'd prefer though if I could actually separate it into several methods, otheriwse I'd sort of lose the point of using WCF.
Yrlec