0

Let's say I have a scenario where I have a Service that is responsible for retrieving the price of a single product given the ID and another Service that gives me the current stock position of it.

It's okay when I'm looking only at one product, but what about a list page where I have 60 products? What should I do in this case? Call the service product by product to retrieve it's current price and stock position?

I think this would be extremely slow and cost a lot of resources. But what could I do to make it look good and at the same time have performance?

Currently we have these information in the database in a column next to the product. These price and stock columns are updated by a sql service that updates it when is necessary so when I need to grab the value for a lot of products at the same time I just need to select two columns more. It's really fast, but right now we have some more systems in need of this information and I would like to transform all these stuff in a service.

Thanks a lot!

tucaz
  • 6,524
  • 6
  • 37
  • 60

2 Answers2

2

Well, you could always have multiple service methods:

  • the one you already have, to retrieve a single product, and the price for a single product
  • create a new service method which would take a list of product ID's, and return a list of product objects - or a new DTO (data-transfer object) that holds product and price

This way, you could keep your current users happy, and also do something to make batch requests work more efficiently.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • I thought of that marc_s, but it doen't seems to me very "SOA", you know what I mean? I know it's odd, but it doesn't look good. Maybe my mindset is not correct. But let's say I'll do it. After calling the batch service I would have to merge the data returned from service with the rest of the data I have and it does not smells good too. How it sounds to you? Thanks a lot, man. – tucaz Dec 02 '09 at 20:20
  • I don't agree - either way, if you have to check the price and product info for 60 products, it'll be a loop or something. I don't see how that extra service method should "not be SOA"...... – marc_s Dec 02 '09 at 20:26
  • I know it makes sense, but I just don't like it...eeheheheh I guess it's my mindset. What would you say about the merge? It's how you would do? Thanks, again. – tucaz Dec 02 '09 at 20:31
  • I don't totally understand your "merge" question part.... merge where and why and what?? Can't you make your service return all the bits of information you need? If not - well, yes, then you have to merge that information from the service with other information somehow - that's raelly not dependent on WCF or your service design.... – marc_s Dec 03 '09 at 06:13
0

Can your service method take an array of IDs? And return an array of values? That way if you want one record your array only has 1 item, if you want more, you just populate the array with multiple values?

Jeremy
  • 44,950
  • 68
  • 206
  • 332
  • Could you please answer http://stackoverflow.com/questions/9553267/design-parameter-decision ? – LCJ Mar 04 '12 at 09:47