为什么通过静态页面方法将Web服务与Ajax一起使用? [英] Why use a web service with ajax over a static page method?

查看:171
本文介绍了为什么通过静态页面方法将Web服务与Ajax一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个使用jquery ajax发布值的aspx页面,这些值由页面后面的代码处理,并通过Json返回.我已经创建了一个Web服务来执行此操作,但是我最好在页面上使用静态方法来执行此操作吗?参照ajax使用Web服务的优缺点是什么?

I'm building an aspx page that uses jquery ajax to post values, which are processed by a code behind page, 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?

推荐答案

对于您的特定情况,使用哪种方法都没有多大关系,因为您可能仅会使用几种方法中的AJAX来使用其中的几种方法特定页面.您需要的是一些服务器端处理和一个返回类型,可以很容易地从Javascript中使用它,并且可以使用Web服务和Web页面(或仅是ASP .Net HTTP处理程序)来完成此操作.

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.

从体系结构的角度来看,如果要由多个客户端使用该功能,则应该构建一个Web服务.通过这样做,您可以封装服务公开的功能,还可以更好地控制返回结果,安全性,限制和与Web服务相关的其他方面的不同格式.

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.

在特定情况下,仅实现某些AJAX方法时,直接在ASP .Net Web应用程序中直接构建服务可能会更方便,因为它避免了完整服务的配置和部署复杂性.

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.

希望这会有所帮助.

关于,
弗洛林

Regards,
Florin

这篇关于为什么通过静态页面方法将Web服务与Ajax一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆