Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With Marc Gravell's help, I understood how nested classes work in protobuf.</p> <p>I tested it with a ServiceStack (ver. 3.9.71) service, and it works fine.</p> <p>here is the model.</p> <pre><code>using System.Xml.Serialization; [XmlType("Person")] public class Person { [XmlElement(ElementName = "Display Name", Order = 1)] public string Name { get; set; } [XmlElement(ElementName = "Age", Order = 2)] public byte Age { get; set; } [XmlElement(ElementName = "Contact Address", Order =3)] // the address instance public Address ContactAddress { get; set; } [XmlElement(ElementName = "Person Id", Order = 4)] public int Id { get; set; } [XmlType("Person.Address")] public class Address { [XmlElement(ElementName = "Street", Order = 1)] // before I had Order=5 to be unique, but as Mark says // the "Order only needs to be unique inside a single type" public string Street { get; set; } [XmlElement(ElementName = "ZIP", Order = 2)] public string Zip { get; set; } } } </code></pre> <p>the ServiceStack Requests</p> <pre><code> public class PersonRequest { public string Zip { get; set; } public byte Age { get; set; } public int Id { get; set; } } public class AddressRequest { public string Zip { get; set; } } </code></pre> <p>the ServiceStack Routes in AppHost.Configure. ( self-hosted service)</p> <pre><code> Routes .Add&lt;PersonRequest&gt;("/Person/{Id}", "GET, OPTIONS") .Add&lt;PersonRequest&gt;("/Persons/{Zip}", "GET, OPTIONS") .Add&lt;AddressRequest&gt;("/Addresses/{Zip}", "GET, OPTIONS"); </code></pre> <p>the services </p> <p>First case, we ask a list of Persons with Contact Address using Zip filter</p> <p>Second case, a list of Addresses using Zip filter, unrelated to Persons</p> <pre><code>public List&lt;Person&gt; Get(PersonRequest request) { List&lt;Person&gt; persons=new List&lt;Person&gt;(); persons.Add(new Person() { Name = "stefan", ContactAddress = new Person.Address(){Street="North Pole"}}); return persons; } public List&lt;Person.Address&gt; Get(AddressRequest request) { // it returns only addresses filtered by Zip List&lt;Person.Address&gt; addresses=new List&lt;Person.Address&gt;(); addresses.Add( new Person.Address() { Street = "North Pole" } ); return addresses; } </code></pre> <p>the ServiceStack client code, using the ProtoBufServiceClient</p> <pre><code> using ServiceStack.Plugins.ProtoBuf; ... var client = new ProtoBufServiceClient(serverUri); List&lt;Person&gt; persons = client.Get&lt;List&lt;Person&gt;&gt;(serverUri + @"/Persons/600617"); List&lt;Person.Address&gt; addresses = client.Get&lt;List&lt;Person.Address&gt;&gt;(serverUri + @"/Addresses/600617"); </code></pre> <p>thanks a lot, Marc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload