views:

362

answers:

2

Is there any difference in using one over the other?

Should I be retrieving data from a database using web services? Or is it better to call methods from code-behind (or somewhere similar) with ajax to retrieve data?

+1  A: 

When you say "calling methods from codebehind", what are you referring to? Do you mean "page methods"? Those are web services, just limited ones.

John Saunders
yes, page methods. Ah, ok, so is there any benefit to using [WebMethod]'s in a Web Service as compared to page methods?
Matt
Page methods are restricted to being called only by your AJAX application. In general, a web service can be created so that it can be called by multiple applications. If that's not important to you, and if you don't need any of the features of WCF, then you have no need to change.
John Saunders
Perfect, thanks.
Matt
+1  A: 

A lot of times, when someone says "Web services", they mean SOAP compliant web services. If they do, then there are a lot of differences. If they just mean a service with an HTTP interface, then calling code-behind meets that requirement.

The main difference that you might care about is SOAP is a cross-language/cross-platform standard that other kinds of frameworks provide support for. So, if you mean to expose your service to other clients (aside from yourself), it might be easier for them to consume. It isn't the only choice -- you could just define a simple REST-based style service.

Calling Page-methods via some ASP.NET only mechanism would be hard for other clients, if you care.

Lou Franco