WCF: Exposed Object Model - stuck in a loop

371 Views Asked by At

I'm working on a pretty big WSSF project. I have a normal object model in the business layer. Eg a customer has an orders collection property, when this is accessed then it loads from the data layer (lazy loading). An order has a productCollection property etc etc..

Now the bit I'm finding tricky is exposing this via WCF. I want to export a collection of orders. The client app will also need information about the customers. Using the WSSF data contract designer I have set it up so that customers have a property called "order collection". This is fine if you have a customer object and would like to look at the orders but if you have an order object there is no customer property so it doesn't work going up the hierarchy.

I've tried adding a customer property to the orders object but then the code gets stuck in a loop when it loads the data contracts up. This is because it doesn't load on demand like in the business layer. I need to load all properties up before the objects can be sent out via WCF. It ends up loading an order, then the customer for that order, then the orders for that customer, then the customer for that order etc etc...

I'm sure I've got all this wrong. Help!!

1

There are 1 best solutions below

2
On

Generally, with WCF, it's best to think of contracts not as 'remote objects', but as interfaces that you can call to get data from or pass data to.

Any methods called on a returned object are processed locally, rather than where the object originated. In fact, getting the 'same' object from the server twice will generally result in two entirely separate objects on the client side!

To get the kind of functionality you're asking about, you would probably need to write some client-side code to create a remote object 'illusion' for you.