WCF 和 ASMX Web 服务之间有什么区别?

发布于 2024-08-25 09:00:06 字数 147 浏览 3 评论 0 原文

我对 WCF 和 ASMX Web 服务完全感到困惑。我前期用过很多Web服务,现在引入了一个新的东西,叫做WCF。我仍然可以创建作为 Web 服务运行的 WCF。我想WCF里还会有更多的东西。

WCF 和 Web 服务之间有什么区别?每一项应该在什么时候使用?

I am totally confused between WCF and ASMX web services. I have used a lot of web services in my earlier stage, and now there is this new thing introduced called WCF. I can still create WCF that function as a web service. I think there will be more stuff in WCF.

What are the differences between WCF and Web services? When should each one be used?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梓梦 2024-09-01 09:00:06

Keith Elder 在这里很好地比较了 ASMX 与 WCF。一探究竟。

ASMX 和 WCF 的另一个比较可以此处找到 -我并不 100% 同意其中的所有观点,但它可能会给你一个想法。

WCF 基本上是“类固醇上的 ASMX”——它可以是 ASMX 所能做到的一切——加上更多!

ASMX 是:

  • 易于编写和配置
  • 仅在 IIS 中可用
  • 只能从 HTTP 调用

WCF 可以:

  • 托管在 IIS、Windows 服务、Winforms 应用程序、控制台应用程序中 - 您可以完全自由地
  • 使用 HTTP(REST 和 SOAP) 、TCP/IP、MSMQ 以及更多协议

简而言之:WCF 将完全取代 ASMX。

请查看 MSDN 上的 WCF 开发人员中心

更新:链接似乎已失效 - 试试这个:什么是 Windows Communication Foundation?

Keith Elder nicely compares ASMX to WCF here. Check it out.

Another comparison of ASMX and WCF can be found here - I don't 100% agree with all the points there, but it might give you an idea.

WCF is basically "ASMX on stereoids" - it can be all that ASMX could - plus a lot more!.

ASMX is:

  • easy and simple to write and configure
  • only available in IIS
  • only callable from HTTP

WCF can be:

  • hosted in IIS, a Windows Service, a Winforms application, a console app - you have total freedom
  • used with HTTP (REST and SOAP), TCP/IP, MSMQ and many more protocols

In short: WCF is here to replace ASMX fully.

Check out the WCF Developer Center on MSDN.

Update: link seems to be dead - try this: What Is Windows Communication Foundation?

北凤男飞 2024-09-01 09:00:06

ASMX Web 服务只能通过 HTTP 调用(带有 .asmx 的传统 Web 服务)。而 WCF 服务或 WCF 组件可以由任何协议(如 http、tcp 等)和任何传输类型调用。

其次,ASMX Web 服务不灵活。然而,WCF 服务很灵活。如果您制作了服务的新版本,那么您只需要公开一个新的端。因此,服务是敏捷的,这是针对当前业务趋势的非常实用的方法。

我们将 WCF 开发为契约、接口、操作和数据契约。作为开发者,我们更专注于业务逻辑服务,无需担心通道堆栈。 WCF 是适用于任何类型服务的统一编程 API,因此我们创建服务并使用配置信息来设置 HTTP/TCP/MSMQ 等通信机制

ASMX Web services can only be invoked by HTTP (traditional webservice with .asmx). While WCF Service or a WCF component can be invoked by any protocol (like http, tcp etc.) and any transport type.

Second, ASMX web services are not flexible. However, WCF Services are flexible. If you make a new version of the service then you need to just expose a new end. Therefore, services are agile and which is a very practical approach looking at the current business trends.

We develop WCF as contracts, interface, operations, and data contracts. As the developer we are more focused on the business logic services and need not worry about channel stack. WCF is a unified programming API for any kind of services so we create the service and use configuration information to set up the communication mechanism like HTTP/TCP/MSMQ etc

何其悲哀 2024-09-01 09:00:06

这是一个非常古老的问题,但我认为 ASMX 的好处还没有被充分描述。虽然不太灵活,但 ASMX Web 服务非常易于使用和理解。虽然 WCF 更灵活,但其安装和配置也更复杂。

添加文件后,ASMX Web 服务即可启动并添加为 Web 服务引用。 (假设您的项目已构建)

对于简单的开发工作流程
创建网络服务 -> 运行网络服务 -> 添加 Web 服务引用,ASMX Web 服务几乎不会出错,也不会发生太多配置错误,这就是它的优势。

针对那些断言WCF取代ASMX的人,我会回复说WCF需要添加简化的KISS配置模式才能完全取代ASMX。

ASMX Web 服务的 web.config 示例:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings />
  <system.web>
    <compilation targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
</configuration>

This is a very old question, but I do not feel that the benefits of ASMX have been fairly portrayed. While not terribly flexible, ASMX web services are very simple to use and understand. While WCF is more flexible, it is also more complex to stand up and configure.

ASMX web services are ready to stand up and add as a webservice reference as soon as you add the file. (assuming your project builds)

For the simple development workflow of
create webservice -> run webservice -> add webservice reference, an ASMX webservice has very little that can go wrong, not much that you can misconfigure, and that is it's strength.

In response to those that assert that WCF replaces ASMX, I would reply that WCF would need to add a streamlined K.I.S.S. configuration mode in order to completely replace ASMX.

Example web.config for an ASMX webservice:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings />
  <system.web>
    <compilation targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
</configuration>
万人眼中万个我 2024-09-01 09:00:06

WCF 完全取代了 ASMX Web 服务。 ASMX 是执行 Web 服务的旧方法,而 WCF 是当前执行 Web 服务的方法。所有新的 SOAP Web 服务开发,无论是在客户端还是服务器上,都应该使用 WCF 来完成。

WCF completely replaces ASMX web services. ASMX is the old way to do web services and WCF is the current way to do web services. All new SOAP web service development, on the client or the server, should be done using WCF.

寻找一个思念的角度 2024-09-01 09:00:06

关于 WCF 上的 asmx Web 服务的简单性有很多讨论。让我在这里澄清几点。

  • 确实,新手 Web 服务开发人员可以轻松上手 asmx Web 服务。 Visual Studio 为他们完成所有工作并轻松创建一个 Hello World 项目。
  • 但如果你能学会WCF(当然不会花太多时间)那么你就会发现WCF也很简单,你可以轻松地继续。
  • 重要的是要记住,WCF 中的这些复杂性实际上归因于它带来的美丽功能。有寻址、绑定、合同和端点、服务和服务。配置文件中提到的所有客户端。美妙之处在于您的业务逻辑被隔离并安全地维护。明天,如果您需要将绑定从 basicHttpBinding 更改为 netTcpBinding,您可以轻松地在配置文件中创建绑定并使用它。因此,与客户端、通信通道、绑定等相关的所有更改都将在配置中完成,从而保证业务逻辑的安全和安全。完好无损,这确实很有道理。
  • WCF“Web 服务”是通过 WCF 实现的更广泛的远程通信的一部分。与通过传统的 ASMX 相比,您将在 WCF 中获得更高程度的灵活性和可移植性,因为 WCF 的设计从头开始,总结了 Microsoft 提供的所有不同的分布式编程基础结构。 WCF 中的端点可以像通过 TCP/二进制一样轻松地通过 SOAP/XML 进行通信,并且只需配置一个配置文件 mod 即可更改此介质。理论上,这减少了移植或更改业务需求、目标等时所需的新代码量。Web
  • 服务只能通过 HTTP 和 HTTP 访问。它在无状态环境中工作,WCF 非常灵活,因为它的服务可以托管在不同类型的应用程序中。您可以在控制台、Windows 服务、IIS 和 Windows 中托管 WCF 服务。 WAS,这又是在 Visual Studio 中创建新项目的不同方式。
  • ASMX 比 WCF 更老,ASMX 能做到的任何事情也能做到 WCF(以及更多)。基本上,您可以将 WCF 视为试图在 Microsoft 世界中逻辑地将所有不同的方式组合在一起,使两个应用程序进行通信; ASMX 只是众多方法中的一种,因此现在归入 WCF 功能保护伞下。
  • 您将始终喜欢使用 Visual Studio for NET 4.0 或 4.5,因为它使创建 WCF 服务的过程变得轻松。
  • 主要区别在于 Web 服务使用 XmlSerializer。但 WCF 使用 DataContractSerializer,与 XmlSerializer 相比,它的性能更好。这就是为什么 WCF 的性能比 .NET 中的其他通信技术(如 asmx、.NET 远程处理等)要好得多。

不要忘记,我是那些更喜欢 asmx 服务而不是 WCF 的人之一,但当时我不太了解 WCF服务及其能力。我对 WCF 配置感到害怕。但我敢于并尝试编写自己的一些 WCF 服务,当我了解更多 WCF 时,现在我对 WCF 没有任何限制,我将它们推荐给任何人以及更多人。每个人。
快乐编码!

There's a lot of talks going on regarding the simplicity of asmx web services over WCF. Let me clarify few points here.

  • Its true that novice web service developers will get started easily in asmx web services. Visual Studio does all the work for them and readily creates a Hello World project.
  • But if you can learn WCF (which off course wont take much time) then you can get to see that WCF is also quite simple, and you can go ahead easily.
  • Its important to remember that these said complexities in WCF are actually attributed to the beautiful features that it brings along with it. There are addressing, bindings, contracts and endpoints, services & clients all mentioned in the config file. The beauty is your business logic is segregated and maintained safely. Tomorrow if you need to change the binding from basicHttpBinding to netTcpBinding you can easily create a binding in config file and use it. So all the changes related to clients, communication channels, bindings etc are to be done in the configuration leaving the business logic safe & intact, which makes real good sense.
  • WCF "web services" are part of a much broader spectrum of remote communication enabled through WCF. You will get a much higher degree of flexibility and portability doing things in WCF than through traditional ASMX because WCF is designed, from the ground up, to summarize all of the different distributed programming infrastructures offered by Microsoft. An endpoint in WCF can be communicated with just as easily over SOAP/XML as it can over TCP/binary and to change this medium is simply a configuration file mod. In theory, this reduces the amount of new code needed when porting or changing business needs, targets, etc.
  • Web Services can be accessed only over HTTP & it works in stateless environment, where WCF is flexible because its services can be hosted in different types of applications. You can host your WCF services in Console, Windows Services, IIS & WAS, which are again different ways of creating new projects in Visual Studio.
  • ASMX is older than WCF, and anything ASMX can do so can WCF (and more). Basically you can see WCF as trying to logically group together all the different ways of getting two apps to communicate in the world of Microsoft; ASMX was just one of these many ways and so is now grouped under the WCF umbrella of capabilities.
  • You will always like to use Visual Studio for NET 4.0 or 4.5 as it makes life easy while creating WCF services.
  • The major difference is that Web Services Use XmlSerializer. But WCF Uses DataContractSerializer which is better in Performance as compared to XmlSerializer. That's why WCF performs way better than other communication technology counterparts from .NET like asmx, .NET remoting etc.

Not to forget that I was one of those guys who liked asmx services more than WCF, but that time I was not well aware of WCF services and its capabilities. I was scared of the WCF configurations. But I dared and and tried writing few WCF services of my own, and when I learnt more of WCF, now I have no inhibitions about WCF and I recommend them to anyone & everyone.
Happy coding!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文