visual-studio Web 服务——WCF 与 ASMX(“标准”)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Web Services -- WCF vs. ASMX ("Standard")
提问by jdiaz
I am working on a new project. Is there any benefit with going with a WCF web service over a regular old fashion web service?
我正在做一个新项目。与常规的旧式 Web 服务相比,使用 WCF Web 服务有什么好处吗?
Visual Studio offers templates for both. What are the differences? Pros and cons?
Visual Studio 为两者提供模板。有什么区别?利弊?
采纳答案by Nathan
What is a "regular old fashioned web service?" An ASMX service, or are you using WSE as well? ASMX services are not naturally interoperable, don't support WS-* specs, and ASMX is a technology that is aging very quickly. WSE (Web Service Enhancements) services DO add support for WS-* and can be made to be interoperable, but WCF is meant to replace WSE, so you should take the time to learn it. I would say that unless your application is a quick an dirty one-off, you will gain immense flexibility and end up with a better design if you choose WCF. WCF doeshave a learning curve beyond a [WebMethod] attribute, but the learning curve is over-exaggerated in my opinion, and it is exponentially more powerful and future proof than legacy ASMX services.
什么是“常规的老式 Web 服务”?ASMX 服务,还是您也在使用 WSE?ASMX 服务天生就不能互操作,不支持 WS-* 规范,而且 ASMX 是一种老化得非常快的技术。WSE(Web 服务增强)服务确实添加了对 WS-* 的支持,并且可以实现互操作,但 WCF 旨在取代 WSE,因此您应该花时间学习它。我会说,除非您的应用程序是一次性的,否则如果您选择 WCF,您将获得巨大的灵活性并最终获得更好的设计。WCF确实有一个超出 [WebMethod] 属性的学习曲线,但在我看来,学习曲线被夸大了,而且它比传统的 ASMX 服务更强大,更能证明未来。
Unless your time line simply cannot tolerate the learning curve, you would be doing yourself a huge favor learning WCF instead of just sticking with ASP.NET Web Services. Applications will only continue to become more and more distributed and interconnected, and WCF is the future of distributed computing on the Microsoft platform.
除非您的时间线根本无法容忍学习曲线,否则您学习 WCF 而不是仅仅坚持使用 ASP.NET Web 服务会对自己大有帮助。应用程序只会继续变得越来越分布式和互连,而 WCF 是 Microsoft 平台上分布式计算的未来。
Here is a comparisonbetween the two.
回答by doekman
The Pros of doing all by yourself is:
自己做所有事情的好处是:
- No learning curve
- Very flexible
- 没有学习曲线
- 非常灵活
The Pros of WCF are:
WCF的优点是:
- Costs less time in the longer run
- Switch protocols without programming
- 从长远来看,花费更少的时间
- 无需编程即可切换协议
A disadvantage of WCF: some static property names can be pretty lengthy...
WCF 的一个缺点:一些静态属性名称可能很长......
To summarize: WCF lets you focus on programming, but you need to learn it first ;-)
总结一下:WCF 让你专注于编程,但你需要先学习它 ;-)
回答by Andrei R?nea
Pro for WCF : You don't need a web server (i.e. IIS). You actually don't need a server OS.
WCF 专业版:您不需要 Web 服务器(即 IIS)。您实际上不需要服务器操作系统。
回答by Esteban Araya
I like the fact writing WCF services makes it easy to separate your service from the implementation. You can write your service and then host it in IIS, a console application, or a Windows service; you can also talk to it via HTTP, net TCP, etc.
我喜欢这样一个事实:编写 WCF 服务可以轻松地将服务与实现分开。您可以编写服务,然后将其托管在 IIS、控制台应用程序或 Windows 服务中;您还可以通过 HTTP、网络 TCP 等方式与它对话。
回答by Nicolas Dorier
Unit tests on your services implamentation and interaction are easier to do !
对您的服务实现和交互的单元测试更容易进行!
回答by Matt
If your project is using framework 4.0, Why don't your try WebApi, which is easy to understand and uses the convention over configuration.
如果您的项目使用框架 4.0,为什么不试试 WebApi,它易于理解并且使用约定优于配置。
Its a great way of building application with super fast interfaces
它是一种使用超快速接口构建应用程序的好方法
Have look at the getting started videos from MS, It has evolved from WCF data Services.
看看 MS 的入门视频,它是从 WCF 数据服务演变而来的。
http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api
http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api
回答by magallanes
In my experience
在我的经验中
WCF
周转基金
It is absurdly verbose to work with it, it is not quite compatible with other microsoft products and, of course, it is not widely accepted outside ot the microsoft world.
使用它是荒谬的冗长,它与其他微软产品不太兼容,当然,它在微软世界之外并没有被广泛接受。
But my main problem is it is not stable, it trends to fail (in some situation) and it requires to tweak it before it can be used.
但我的主要问题是它不稳定,它趋向于失败(在某些情况下)并且需要在使用之前对其进行调整。
Instead
反而
SOAP (aka standard Webservice), it works, it is easy to work and it is widely compatible (Java-JAX accepts it without any modification).
SOAP(又名标准 Web 服务),它可以工作,易于工作并且具有广泛的兼容性(Java-JAX 无需任何修改即可接受它)。
To add authentication in SOAP could be a bit tricky but not impossible.
在 SOAP 中添加身份验证可能有点棘手,但并非不可能。

