I'm building an aspx page that uses jquery ajax to post values, which are processed by a code behind pa开发者_如何学JAVAge, and passed back via Json. I've created a webservice to do this but am I better using a static method on the page to do this? What are the pros and cons of using a webservice - with reference to ajax?
For your particular situation it does not matter much which approach you are using, since you probably have just a few methods that you are going to consume using AJAX from some specific pages. What you need is some server side processing and a return type that can be easily consumed from Javascript and both a web service and a web page (or just an ASP .Net HTTP handler) can be used to accomplish this.
From an architectural perspective, you should build a web service if that functionality is being to be consumed by multiple clients. By doing this you encapsulate the service exposed functionality and also gain better control on the different formats over which you return the results, security, throttling and other aspects relevant for a web service.
Building the service directly in the ASP .Net web application might be more convenient for the particular case when just implementing some AJAX methods, since it avoids the configuration and deployment complexity of a full service.
Hope this helps.
Regards,
Florin
精彩评论