WCF 和 ASMX Web 服务之间有什么区别?
我对 WCF 和 ASMX Web 服务完全感到困惑。我前期用过很多Web服务,现在引入了一个新的东西,叫做WCF。我仍然可以创建作为 Web 服务运行的 WCF。我想WCF里还会有更多的东西。
WCF 和 Web 服务之间有什么区别?每一项应该在什么时候使用?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Keith Elder 在这里很好地比较了 ASMX 与 WCF。一探究竟。
ASMX 和 WCF 的另一个比较可以此处找到 -我并不 100% 同意其中的所有观点,但它可能会给你一个想法。
WCF 基本上是“类固醇上的 ASMX”——它可以是 ASMX 所能做到的一切——加上更多!。
ASMX 是:
WCF 可以:
简而言之: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:
WCF can be:
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?
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
这是一个非常古老的问题,但我认为 ASMX 的好处还没有被充分描述。虽然不太灵活,但 ASMX Web 服务非常易于使用和理解。虽然 WCF 更灵活,但其安装和配置也更复杂。
添加文件后,ASMX Web 服务即可启动并添加为 Web 服务引用。 (假设您的项目已构建)
对于简单的开发工作流程
创建网络服务
->运行网络服务
->添加 Web 服务引用
,ASMX Web 服务几乎不会出错,也不会发生太多配置错误,这就是它的优势。针对那些断言WCF取代ASMX的人,我会回复说WCF需要添加简化的KISS配置模式才能完全取代ASMX。
ASMX Web 服务的 web.config 示例:
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:
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.
关于 WCF 上的 asmx Web 服务的简单性有很多讨论。让我在这里澄清几点。
不要忘记,我是那些更喜欢 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.
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!!!