views:

644

answers:

1

Hello, I'm trying to consume a WCF webservice using the RPC capabilities of the Protobuf-net. Here's my service contract:

namespace WcfEchoService
{
    // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
    [ServiceContract]
    public interface IEchoService
    {

        [OperationContract, ProtoBehavior]
        string Echo(string value);

        [OperationContract, ProtoBehavior]
        string EchoNull();

        [OperationContract, ProtoBehavior]
        CompositeType[] EchoData(CompositeType[] value);
    }


    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    [ProtoContract]
    public class CompositeType
    {


        [ProtoMember(1)]
        public bool BoolValue
        {
            get;
            set;
        }
        [ProtoMember(2)]
        public string StringValue
        {
            get;
            set;
        }
    }
}

And just below is my .NET CF client:

class EchoServiceClient : ProtoClient, IEchoService {

    #region IEchoService Members

    public EchoServiceClient() : base(new HttpBasicTransport("my service URI"))
    {

    }

    public string Echo(string value)
    {
        return (string)this.Invoke("Echo", value);
    }

    public string EchoNull()
    {
        return (string)this.Invoke("EchoNull");
    }

    public CompositeType[] EchoData(CompositeType[] value)
    {
        return (CompositeType[])this.Invoke("EchoData", value);
    }

    #endregion
}

And this is how i try to consume the webservice:

class Program
{
    static void Main(string[] args)
    {
        EchoServiceClient client = new EchoServiceClient();
        Console.WriteLine(client.EchoNull());
    }
}

I keep getting an exception with the following message:

Either ContentLength must be set to a non-negative number, or SendChunked set to true in order to perform the write operation when AllowWriteStreamBuffering is disabled.

As far as i can tell after digging in protobuf-net's source code the problem seems to be that there is no content-lenght specified. Is there any other way to consume WCF webservices using protobuf-net serialization in .NET CF or a way to solve this issue?

Marc you're on:)

A: 

Edit: I misread the question; short version: ProtoClient != WCF. They are not compatible.


Compact Framework suffers that the WCF stack lacks all of the necessary extension points for this; in short, you can't use this approach with WCF + CF.

I am aware of various working approaches for protobuf-net with CF, though;

  • have your service return a byte[] or (better) Stream and handle it manually; no, it isn't pretty, but it works
  • you could try the alternative RPC stack included with protobuf-net; I think this works on CF (I'd need to check, though; my memory fails)

The alternative stack is ProtoClient<T>; I honestly can't recall whether it works on CF, and I'm not in a position to check at the moment. it should work on CF, as I remember having to re-implement Expression to get it to compile... some example usage (for both 2.0-style and 3.5-style) are here.

Marc Gravell
Thanks for your reply. I will try to play and see what can i make out of that RPC stack.
Does this include WP7?
Richard Szalay
@Richard - I haven't had much time to look at WP7, other than to get the *core* of v2 working (note v2 is available as source, but is not released). Other than that, the `byte[]` trick certainly should work and has the advantage of simplicity. It came to my notice earlier this week that Silverlight now has some of the previously missing extension points that I might be able to use to hook it in more directly, but I don't know if this includes WP7. Alas, there's just one of me...
Marc Gravell