title: web service pattern that supports lazy loading of all properties
body: <p>I am trying to design an endpoint template for a web service. My main requirement is that the caller is able to specify which properties should be populated in the returned result set.</p>
  
  <p>My service returns large lists (up to 1M records) of partial objects as well as individual full objects such as (rough example XML, sorry it's a little verbose)</p>
  
  <p>List:</p>
  
  <pre><code>&lt;items&gt;
    &lt;item&gt;
      &lt;a&gt;aaa&lt;/a&gt;
      &lt;b&gt;bbb&lt;/b&gt;
    &lt;/item&gt;
    &lt;item&gt;
      &lt;a&gt;aaaA&lt;/a&gt;
      &lt;b&gt;bbbB&lt;/b&gt;
    &lt;/item&gt;
  &lt;/items&gt;
  </code></pre>
  
  <p>Detail:</p>
  
  <pre><code>&lt;item&gt;
    &lt;a&gt;aaa&lt;/a&gt;
    &lt;b&gt;bbb&lt;/b&gt;
    &lt;c&gt;ccc&lt;/c&gt;
    ...
    &lt;w&gt;
      &lt;x&gt;xxx&lt;/x&gt;
      &lt;y&gt;yyy&lt;/y&gt;
    &lt;/w&gt;
    &lt;z&gt;zzz&lt;/z&gt;
  &lt;/item&gt;
  </code></pre>
  
  <p>I have considered the following ideas:</p>
  
  <ol>
  <li>Returning the full detail items in the list</li>
  <li>Creating a 'list' item type that is shorter</li>
  <li>passing a string array of property names that the caller wants to be returned</li>
  </ol>
  
  <p>I am leaning towards the 3rd option but I want something different to that it doesn't support sub objects, I have considered passing the xml schema that you want returned instead of an array.</p>
  
  <p>I would like the API to support lazy loading which is why the 3rd way seems viable as well.</p>
  
  <p>Here's an example of what a function for 3. would look like:</p>
  
  <pre><code>public User GetUser(long ID, string[] properties)
  </code></pre>
  
  <p>And then the caller could just go:</p>
  
  <pre><code>User.Email = GetUser(User.ID, "Email").Email
  </code></pre>
  
  <p>Through extensive use of default values and hiding nulls, the returned XML for that would be:</p>
  
  <pre><code>&lt;User&gt;
    &lt;ID&gt;123&lt;/ID&gt;
    &lt;Email&gt;example@example.com&lt;/Email&gt;
  &lt;/User&gt;
  </code></pre>
  
  <p>Now the problem as mentioned above is trying to make it play nice with things like <code>&lt;w&gt;</code> far above, which itself has sub items as well as the possibility for lists to have sub items.</p>
  
  <p>As I have far too many properties, I cannot have just a ws method for each property.</p>
  
  <p>I am considering option 3. but using an xml schema instead of a <code>string[]</code>.. But I can't think of an easy way to define this, I would also like to not have to use String names for properties such as <code>"Email"</code>.</p>
  
  <p>The final plan is to have a series of pre-defined schemas that are used commonly and only in advanced cases would we need to actually define the requested properties. But I have no idea of all the systems that will be talking to my API, let alone what properties they might each want (it's not going to be feasible for us to tailor the API for every caller).</p>
  
  <p>Or am I over complicating everything too much?</p>