views:

92

answers:

5

hi,

I am setting up a web service and i'm unsure about the most efficient design..

The web service is going to be called to populate a remote website with a list of people and their associated information. So, in the database there will be a "Person" table, then other tables for nicknames, addresses, phone numbers, etc. There may be 50 "People" returned for the page.

I would think I'd want to keep the # of web service calls to a minimum.. So is the best way to just have one call, GetPeople(), which returns all People and their information in one xml? Or would I want to maybe have GetPeople() return just a list of People, then have a GetPeopleInfo() call for each person?

Thanks in advance

+1  A: 

You need to think about how your service is going to be used.

Will the users require all of that information most/all of the time? If so then it's appropriate for GetAllPeoplesDetails() to return everything

If they're going to only rarely need all the info then GetPeople() should return just a list of People.

If you're not sure then you could provide both GetAllPeoplesDetails() and GetPeople() and let the end user make that decision

Glen
A: 

XML is fine.

JSON is better.

Dave Ward at Encosia uses DataTransferObjects to serialize his "Person" objects.

I keep linking to this article because it's done so well, and this is a common problem.

Hope this helps, JP

Jonathan
+1  A: 

Will you have an opportinuty to talk a bit more with the folks using the web service? The best answer would be depend on a number of factors, including how they are using it.

The simplest soution would be to create one web service method GetPeople() that executes a query joining the Person table with the rest of the tables and returnes all of the data in one flat table. If the client is just going to display all this information in a single list/table this would be the best option all around.

If, on the other hand, the client is going to generate a list of people and then have a click through to get more detailed information on a separate detail page, they might want a GetPeople() method that just returns the names/ids and a GetPeopleInfo() that pulls back the detail. If this isn't going to cause a performance problem on your system, this should be relatively straight forward.

I would probably build both - create a GetPeople() method that brings back all the data {as long as there isn't so much data that transportation becomes and issue} and a GetPersonInfo() method that allows they to pull back details on a specific person. This offers your client the greatest flexibility with not too much additional effort on your part.

James Conigliaro
Thanks- Actually, there will be one page that lists all People with all of their information, and other pages will be showing specific people with their information. So I will definitely need the GetPersonInfo() to be able to display them individually. If each person has about as much information associated with them as the length of your answer to my question (name, multiple addresses, even a paragraph about them), and a page will be displaying up to 50 of these, is a GetAllPeopleAndInfo() a good way of doing this? Is there an amount of data that's just "too much" for one service call?
With just a handfull of fields (even a paragraph about each person) and only fifty or so people, you should definitely be able to pull back and provide all of the data in one shot.
James Conigliaro
Another idea that was brought up was to expose the individual queries ( like GetAddresses(person), GetPhoneNumbers(Person) ) .. but if they are only consuming the service to populate the site as I described above, then it's got to be extremely inefficient for them to call the service multiple times for a Person's specific info as opposed to returning a Person object with all of that in 1 call, right? And if they need individual info about a Person, they could parse the XML response from a fully populated Person. Just looking for confirmation that I'm thinking correctly, thanks again.
A: 

I think your GetPeople() call is appropriate. You can return a very lean result set and the end user can GetPeopleInfo() if they need it. If the result set is large, you may want to provide a paging option and result count in your method that allows the caller to pull back a certain amount of rows at a time.

Coov
+1  A: 

Giving your users options especially when they are disperssed is your best option in my opinion. Having options such as:

GetPeopleList() : return list of people names GetPeopleAll() : Get list of all people and all info GetPersonInfo() : Get info of 1 person

Just my opinion but by giving your people a choice your making your application more usefull to them.

David Yancey