简体   繁体   English

哪一个更适合jQuery.ajax调用? .Net Web服务还是.ashx?

[英]Which one is better for jQuery.ajax calls? .Net Web-Service or an .ashx?

I ahve been practicing jQuery.ajax() recently. 我最近一直在练习jQuery.ajax()。 I have started to learn to call .Net web-services qith jQuery.ajax(). 我已经开始学习调用.Net web-services qith jQuery.ajax()。

Now I am considering if I will use only jQuery.ajax() calls to some service methods on the server; 现在我正在考虑是否使用jQuery.ajax()调用服务器上的一些服务方法; is it still meaningfull to have .Net Web-Services or I should go with .ashx handlers instead? 有.Net Web服务仍然有意义吗?或者我应该使用.ashx处理程序?

Thanks! 谢谢!

Two quotes from the ASP.NET forums : 来自ASP.NET论坛的两个引用:

Unless it's an extremely high load situation, you'll find that all three perform nearly identically. 除非它是一个极高的负载情况,你会发现这三个表现几乎相同。 The performance of your code inside the handler/service is going to be the limiting factor. 处理程序/服务中的代码性能将成为限制因素。

For simple AJAX calls that are only intended to be exposed to the browser, I don't think WCF justifies its added complexity. 对于仅打算暴露给浏览器的简单AJAX调用,我认为WCF不会证明其增加的复杂性。 It's great for some things, but I have a hard time recommending it for this. 这对某些事情来说很棒,但我很难为此推荐它。

Between ASMX and HttpHandler, I go with ASMX every time. 在ASMX和HttpHandler之间,我每次都使用ASMX。 An HttpHandler is probably negligibly faster, but an ASMX "ScriptService" makes JSON serialization and deserialization of complex types transparent, which is immensely useful. HttpHandler可能会快得多,但是ASMX“ScriptService”使复杂类型的JSON序列化和反序列化变得透明,这非常有用。


Here's another option: 这是另一种选择:

If you have some methods you want to run (and you like JQuery)... I suggest looking at this: 如果你有一些想要运行的方法(而且你喜欢JQuery)...我建议看看这个:

http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/ http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/

and related articles. 和相关文章。 Works beautiful. 工作很美。 Very efficient as far as bandwith goes. 带宽非常有效。 They also have an article on querying .asmx services. 他们还有一篇关于查询.asmx服务的文章。

There is no messing around with the bloated size of ASP.NET's innate AJAX. ASP.NET的先天AJAX的膨胀大小并没有搞乱。 Since AJAX out of the box can be very bloated. 由于开箱即用的AJAX可能非常臃肿。 Plus it's very easy. 而且它很容易。

You should also have a look at microsoft's most recent framework for web services: WebAPI 您还应该看看microsoft最新的Web服务框架: WebAPI

Personally, I recently switched to ServiceStack.NET for my web services, and I find it's a lot easier and elegant (than WebAPI, or WCF). 就个人而言,我最近切换到ServiceStack.NET用于我的Web服务,我发现它比WebAPI或WCF更容易和更优雅。

WCF服务将是ASP.NET soap Web服务或ashx服务的首选方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM