title: Wiring up returned object instances in a WCF client
body: <p>I have a WCF service that can return several different collections.</p>
  
  <p>Objects in each collection can have references to objects in the other collections. Eg. I have a collection of orders, and a collection of customers. Customer objects contain a collection of order references, and each order contains a customer reference.</p>
  
  <p>I was wondering how people generally handle this kind of thing on the client side. As far as I can see, my choices are:</p>
  
  <p>1) Just let WCF serialise any member objects in full, and don't worry about duplication. I know I can use [PreserveReferences] to mitigate this to some extent, but there is still an awful lot of duplication and unnecessary serialisation going on. Ie, if I request a customer object from the service, it will serialise all members of every order that the customer has, even though I already have those objects on the client side in my orders collection. This also means I must be careful to match things by Id all the time rather than just comparing instances.</p>
  
  <p>2) Serialise Id's rather than instances. This seems like the most sensible approach, but means I have to have some point where I turn these Id's into instances again on the client side. This brings a whole mess of where to do this, and how to inject the required repositories to do the wiring up.</p>
  
  <p>3) Just use Id's everywhere in the client instead of wiring up instances. This just feels wrong to me, and moving away from the whole point of OOP. Instead of accessing a collection on the object, I have to access a collection of id's and then look them up via some global repository.</p>
  
  <p>At the moment I'm leaning towards 2, but am not liking the serialisation mess this is going to be. </p>
  
  <p>I should note that the client is probably a lot more stateful than most WCF clients, and it maintains an open connection to the service with callbacks etc to maintain its collections, since it is displaying realtime data.</p>
  
  <p>Cheers</p>