tags:

views:

94

answers:

1

Hi

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!!

A: 

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.

kyoryu
Hi KyoryuThanks for the response. Actually I understand that they are data contracts and not full-blown business objects. The thing is I want to send some data so why not send it as a collection of objects (data contracts) with properties that are collections of other data contracts. I guess I'm realising now that it's not possible because of the loop issue. I suppose I'll just return a collection of simple order objects that have a property of customerId. Then client code can loop through the order collection and load up the customers. This will be slower but hopefully correct? -Cheers Mark
Mark Evans
I'd probably avoid that - whenever possible, you want calls to your service to be atomic. If it's that big of an issue due to the cycle, consider using separate DataContracts for Orders that have Customers included, and Customers that have Orders attached. And, of course, you could always just leave one of the properties null if you wanted to... Are you using separate data transfer objects, or just trying to return "raw" business objects with logic?
kyoryu