gpt4 book ai didi

asp.net - 它应该是 WebAPI 还是 asmx

转载 作者:行者123 更新时间:2023-12-03 21:24:17 28 4
gpt4 key购买 nike

我应该为我的两个简单 API 使用 ASMX 服务还是 ASP.NET Web API?

我想在我的 ASP.NET MVC 项目中创建两个简单的 API。一个接受 3 个参数( currentUserIDDataTypeActionName )。它返回它们和它们请求的数据的 XML 字符串。 API 由客户端 JavaScript 代码使用。另一个 API 接收 XML 字符串并在服务器端使用该字符串对数据库执行操作。

最佳答案

我刚刚回答了一个相关的问题:
What is the future of ASP.NET MVC framework after releasing the asp.net Web API
基本上,微软提供的开发 Web 服务的框架有:

  • ASMX。基于 SOAP 的 XML 服务。
  • WCF。基于 SOAP 的 Web 服务。这些服务是传统 ASMX 服务的演变,基本上它们专注于将服务本身与传输协议(protocol)分开。这就是为什么您可以使用多个端点公开相同的服务,因此可以使用多个协议(protocol)(TCP、HTTP、命名管道、MSMQ、HTTPS)。这种灵 active 伴随着配置问题。社区中对 WCF 的主要提示之一是繁琐且广泛的配置
  • 网页 API。基于不在 SOAP 中的 HTTP。这个新的 API 是一个创建服务的新框架。与其他两个前辈的主要区别在于它基于 HTTP 而不是 SOAP,因此您可以使用几个 HTTP 功能,例如:
  • 它包含非常有意义和描述性的消息头 - 建议消息正文内容类型的头,解释如何缓存信息,如何保护信息的头等。
  • 使用动词来定义 Action (POST、PUT、DELETE..)
  • 它包含一个可用于发送任何类型内容的正文
  • 它使用 URI 来识别信息路径(资源)和操作

  • WEB API 专注于编写服务以通过 HTTP 公开它们(目前仅在 HTTP 上)。如果您想使用其他协议(protocol)公开您的服务,那么您应该考虑使用 WCF。
    WEB API基于MVC(如果你想知道它基于MVC的原因,很简单)

    Another goal of the WCF Web APIs was to incorporate known concepts that would help developers to overcome some of the drawbacks they faced with WCF, such as huge configurations, overuse of attributes, and the WCF infrastructure that did not support testing well. Thus the Web APIs used IoC, enabled convention-over-configuration, and tried to offer simpler configuration environment.

    ASP.NET MVC infrastructure with its elegant handling of HTTP requests and responses, and its support of easy-to-create controllers seemed like the proper way to go for creating this new type of services.



    考虑以下几点来选择 WCF 或 WEB API
    • If your intention is to create services that support special scenarios – one way messaging, message queues, duplex communication etc, then you’re better of picking WCF
    • If you want to create services that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transports are unavailable, then you’re better off with WCF and using both SOAP-based bindings and the WebHttp binding.
    • If you want to create resource-oriented services over HTTP that can use the full features of HTTP – define cache control for browsers, versioning and concurrency using ETags, pass various content types such as images, documents, HTML pages etc., use URI templates to include Task URIs in your responses, then the new Web APIs are the best choice for you.
    • If you want to create a multi-target service that can be used as both resource-oriented service over HTTP and as RPC-style SOAP service over TCP – talk to me first, so I’ll give you some pointers.

    更详细的比较:
    http://www.codeproject.com/Articles/341414/WCF-or-ASP-NET-Web-APIs-My-two-cents-on-the-subjec

    关于asp.net - 它应该是 WebAPI 还是 asmx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11643072/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com