我是protobuf的新手,對asp.net很新。所以我可能需要幫助。我有這樣的代碼片段我PersonsController:使用C#ASP .NET web api發送Protobuf序列化數據需要做什麼?
public class PersonController : ApiController
{
[ProtoContract]
public class Person
{
[ProtoMember(1)]
public int ID { get; set; }
[ProtoMember(2)]
public string First { get; set; }
[ProtoMember(3)]
public string Last { get; set; }
}
// GET api/values
public IEnumerable<Person> Get()
{
List<Person> myList = new List<Person> {
new Person { ID = 0, First = "Judy", Last = "Lee" },
new Person { ID = 1, First = "John", Last = "Doe" },
new Person { ID = 2, First = "George", Last = "Poole" },
};
return myList;
}
}
,我想知道如果這足以能夠送出去的protobuf數據和其他應用程序使用?
我試圖直接在谷歌瀏覽器中訪問它,我得到的是XML格式的數據。
<ArrayOfPersonController.Person xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/SampleSerialize.Controllers">
<PersonController.Person>
<First>Judy</First>
<ID>0</ID>
<Last>Lee</Last>
</PersonController.Person>
<PersonController.Person>
<First>John</First>
<ID>1</ID>
<Last>Doe</Last>
</PersonController.Person>
<PersonController.Person>
<First>George</First>
<ID>2</ID>
<Last>Poole</Last>
</PersonController.Person>
</ArrayOfPersonController.Person>
我怎麼知道,如果我能發出序列化的數據?
應定義數據格式發送出去您的API,XML,JSON,純文本等 – DanielVorph
這將有助於http://www.infoworld.com/article/2982579/application-architecture/working- with-protocol-buffers-in-web-api.html – Jehof