Asp.net web api 在客户端使用WebApiContrib ProtobufferMatter

Asp.net web api 在客户端使用WebApiContrib ProtobufferMatter,asp.net-web-api,protobuf-net,Asp.net Web Api,Protobuf Net,我正在使用WebApiContrib.Formatting.ProtoBuf NuGet包()在我的Web API项目中添加对协议缓冲区的支持 服务器端似乎工作得很好,但我无法让Web API客户端库对服务器响应进行反序列化 System.InvalidOperationException: Type is not expected, and no contract can be inferred: System.Collections.Generic.IEnumerable`1[[WebAPI

我正在使用WebApiContrib.Formatting.ProtoBuf NuGet包()在我的Web API项目中添加对协议缓冲区的支持

服务器端似乎工作得很好,但我无法让Web API客户端库对服务器响应进行反序列化

System.InvalidOperationException: Type is not expected, and no contract can be inferred: System.Collections.Generic.IEnumerable`1[[WebAPITest1.Protocol.Messages.Product, WebAPITest1.Protocol.Messages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
这是我的客户代码:

var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri(@"http://localhost:60500/");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-protobuf"));
var response = httpClient.GetAsync("/api/products?$orderby=Name").Result;
Assert.IsTrue(response.IsSuccessStatusCode);

var products = response.Content.ReadAsAsync<IEnumerable<Product>>(new[]{new ProtoBufFormatter()}).Result;
Assert.IsTrue(products.Count() > 0);
var-httpClient=new-httpClient();
httpClient.BaseAddress=新Uri(@“http://localhost:60500/");
httpClient.DefaultRequestHeaders.Accept.Add(新的MediaTypeWithQualityHeaderValue(“应用程序/x-protobuf”);
var response=httpClient.GetAsync(“/api/products?$orderby=Name”).Result;
Assert.IsTrue(response.issucessStatusCode);
var products=response.Content.ReadAsAsync(new[]{new protobuffermatter()});
Assert.IsTrue(products.Count()>0);

想法?

除了
IEnumerable
之外,您是否尝试过其他方法?特别是,可能是具有一组
产品的顶级对象?例如:

[ProtoContract]
public class NeedsBetterName {
    [ProtoMember(1)]
    public List<Product> Products {get;set;}
}
[协议]
公共类需要指定名称{
[原成员(1)]
公共列表产品{get;set;}
}

那可能会更快乐。实际上,我在本月早些时候(r629中)添加了对“裸枚举”更好的支持,但是,我还没有在任何地方部署此构建。

这确实有效,尽管在我的例子中,我试图公开OData端点。至少在使用WebAPI时,我不知道如何告诉WebAPI将结果封装在这样的容器类中。你知道什么时候可以公开这个功能吗?@RMD我这周在远程工作,没有访问我通常的虚拟机进行干净的构建/回归测试;我可以运行一个正确的建设下一周伟大!谢谢你,马克。我们刚刚开始一个新的项目,很高兴提供protobuf作为一个选项。有什么更新吗?我肯定你是个大忙人,很抱歉打扰你。刚刚抓到你的最新版本,问题就解决了。谢谢@Marc!