WCF和传统ASP.NET Web之间有什么区别

时间:2022-04-27 17:18:14

I am new to WCF and Web Services in general. What are the improvements that WCF brings to the table? Can anyone give a side-by-side example of a traditional web service and the same one written using WCF and point out the differences and advantages?

我是WCF和Web服务的新手。 WCF带来了哪些改进?任何人都可以提供传统Web服务的并排示例,以及使用WCF编写的同一个例子并指出差异和优势吗?


Duplicate question Moving ASP.net webservices to WCF

重复的问题将ASP.net webservices移动到WCF

3 个解决方案

#1


EDIT: Think i found the answer you where looking for a side-by-side code based comparison and even better it's from MSDN: Comparing ASP.NET Web Services to WCF Based on Development

编辑:想想我找到了你在哪里寻找基于代码的并行代码的答案,甚至更好的是来自MSDN:将ASP.NET Web服务与基于开发的WCF进行比较

There are several related questions:

有几个相关的问题:

However you asked for a side by side comparison in which case i think Sam's Wcf vs ASMX blog article is more what you are looking for.

然而,你要求进行并排比较,在这种情况下,我认为Sam的Wcf vs ASMX博客文章更多是你正在寻找的。

Quoting ad-verbatim (let me know if i should just leave it as a link):

引用ad-verbatim(请告诉我是否应将其保留为链接):

WCF vs. ASMX

WCF与ASMX

Protocols Support

WCF

  • HTTP
  • TCP
  • Named pipes
  • MSMQ
  • Custom
  • UDP

ASMX

  • HTTP only

Hosting

ASMX

  • Can be hosted only with HttpRuntime on IIS.
  • 只能在IIS上使用HttpRuntime进行托管。

WCF

  • A WCF component can be hosted in any kind of environment in .NET 3.0, such as a console application, Windows application, or IIS.
  • WCF组件可以托管在.NET 3.0中的任何类型的环境中,例如控制台应用程序,Windows应用程序或IIS。

  • WCF services are known as 'services' as opposed to web services because you can host services without a web server.
  • WCF服务被称为“服务”而不是Web服务,因为您可以在没有Web服务器的情况下托管服务。

  • Self-hosting the services gives you the flexibility to use transports other than HTTP.
  • 自托管服务使您可以灵活地使用HTTP以外的传输。

WCF Backwards Compatibility

WCF向后兼容性

  • The purpose of WCF is to provide a unified programming model for distributed applications.
  • WCF的目的是为分布式应用程序提供统一的编程模型。

  • Backwards compatibility
  • WCF takes all the capabilities of the existing technology stacks while not relying upon any of them.
  • WCF具有现有技术堆栈的所有功能,而不依赖于任何技术堆栈。

  • Applications built with these earlier technologies will continue to work unchanged on systems with WCF installed.
  • 使用这些早期技术构建的应用程序将在安装了WCF的系统上继续保持不变。

  • Existing applications are able to upgrade with WCF
  • 现有应用程序可以使用WCF进行升级

  • New WCF transacted application will work with existing transaction application built on System.Transactions
  • 新的WCF事务处理应用程序将与基于System.Transactions构建的现有事务应用程序一起使用

WCF & ASMX Integration

WCF和ASMX集成

  • WCF can use WS-* or HTTP bindings to communicate with ASMX pages
  • WCF可以使用WS- *或HTTP绑定与ASMX页面进行通信

Limitations of ASMX:

ASMX的局限性:

  • An ASMX page doesn’t tell you how to deliver it over the transports and to use a specific type of security. This is something that WCF enhances quite significantly.
  • ASMX页面不会告诉您如何通过传输传递它以及使用特定类型的安全性。这是WCF非常显着的增强。

  • ASMX has a tight coupling with the HTTP runtime and the dependence on IIS to host it. WCF can be hosted by any Windows process that is able to host the .NET Framework 3.0.
  • ASMX与HTTP运行时紧密耦合,并依赖IIS来托管它。 WCF可由任何能够托管.NET Framework 3.0的Windows进程托管。

  • ASMX service is instantiated on a per-call basis, while WCF gives you flexibility by providing various instancing options such as Singleton, private session, per call.
  • ASMX服务基于每个呼叫进行实例化,而WCF通过提供各种实例化选项(如Singleton,私有会话,每次调用)为您提供灵活性。

  • ASMX provides the way for interoperability but it does not provide or guarantee end-to-end security or reliable communication.
  • ASMX提供了互操作性的方式,但它不提供或保证端到端的安全性或可靠的通信。

#2


WCF is far wider in scope than ASP.Net webservices.

WCF的范围远远超过ASP.Net webservices。

  • WCF can run in any application. APS.Net webservices only run in IIS.
  • WCF可以在任何应用程序中运行。 APS.Net webservices仅在IIS中运行。

  • WCF supports models like ReST, Remoting, SOAP, MSMQ etc. ASP.Net only supports SOAP
  • WCF支持ReST,Remoting,SOAP,MSMQ等模型.ASP.Net仅支持SOAP

  • WCF is more configurable.
  • WCF更易于配置。

  • WCF supports a more declarative way of programming. You can get more done with less code.
  • WCF支持更具说明性的编程方式。您可以使用更少的代码完成更多工作。

#3


ASP.NET Web Services are pretty much just that. Web Services. They're SOAP/WSDL based and provide their services only to the web.

ASP.NET Web服务就是这样。网页服务。它们基于SOAP / WSDL,仅向Web提供服务。

WCF Services offer a much more flexible framework. For instance, depending on how the service is defined, it can be a Web Service hosted in IIS which serialized its data via XML and uses the REST model...or it can be a Remote Windows Service that is hosted in it's own process and serializes its data via binary. All of this is achieved using the different Service/Data contracts in WCF.

WCF服务提供了更灵活的框架。例如,根据服务的定义方式,它可以是IIS中托管的Web服务,它通过XML序列化其数据并使用REST模型......或者它可以是托管在其自己的进程中的远程Windows服务,通过二进制序列化其数据。所有这些都是使用WCF中的不同服务/数据合同实现的。

In short...you can make a WCF service look almost identical to a .NET 2.0 Web Service fairly easily but, with a little work, you can do a WHOLE LOT MORE.

简而言之......您可以非常轻松地使WCF服务看起来几乎与.NET 2.0 Web服务相同,但是,通过一些工作,您可以做得更多。

#1


EDIT: Think i found the answer you where looking for a side-by-side code based comparison and even better it's from MSDN: Comparing ASP.NET Web Services to WCF Based on Development

编辑:想想我找到了你在哪里寻找基于代码的并行代码的答案,甚至更好的是来自MSDN:将ASP.NET Web服务与基于开发的WCF进行比较

There are several related questions:

有几个相关的问题:

However you asked for a side by side comparison in which case i think Sam's Wcf vs ASMX blog article is more what you are looking for.

然而,你要求进行并排比较,在这种情况下,我认为Sam的Wcf vs ASMX博客文章更多是你正在寻找的。

Quoting ad-verbatim (let me know if i should just leave it as a link):

引用ad-verbatim(请告诉我是否应将其保留为链接):

WCF vs. ASMX

WCF与ASMX

Protocols Support

WCF

  • HTTP
  • TCP
  • Named pipes
  • MSMQ
  • Custom
  • UDP

ASMX

  • HTTP only

Hosting

ASMX

  • Can be hosted only with HttpRuntime on IIS.
  • 只能在IIS上使用HttpRuntime进行托管。

WCF

  • A WCF component can be hosted in any kind of environment in .NET 3.0, such as a console application, Windows application, or IIS.
  • WCF组件可以托管在.NET 3.0中的任何类型的环境中,例如控制台应用程序,Windows应用程序或IIS。

  • WCF services are known as 'services' as opposed to web services because you can host services without a web server.
  • WCF服务被称为“服务”而不是Web服务,因为您可以在没有Web服务器的情况下托管服务。

  • Self-hosting the services gives you the flexibility to use transports other than HTTP.
  • 自托管服务使您可以灵活地使用HTTP以外的传输。

WCF Backwards Compatibility

WCF向后兼容性

  • The purpose of WCF is to provide a unified programming model for distributed applications.
  • WCF的目的是为分布式应用程序提供统一的编程模型。

  • Backwards compatibility
  • WCF takes all the capabilities of the existing technology stacks while not relying upon any of them.
  • WCF具有现有技术堆栈的所有功能,而不依赖于任何技术堆栈。

  • Applications built with these earlier technologies will continue to work unchanged on systems with WCF installed.
  • 使用这些早期技术构建的应用程序将在安装了WCF的系统上继续保持不变。

  • Existing applications are able to upgrade with WCF
  • 现有应用程序可以使用WCF进行升级

  • New WCF transacted application will work with existing transaction application built on System.Transactions
  • 新的WCF事务处理应用程序将与基于System.Transactions构建的现有事务应用程序一起使用

WCF & ASMX Integration

WCF和ASMX集成

  • WCF can use WS-* or HTTP bindings to communicate with ASMX pages
  • WCF可以使用WS- *或HTTP绑定与ASMX页面进行通信

Limitations of ASMX:

ASMX的局限性:

  • An ASMX page doesn’t tell you how to deliver it over the transports and to use a specific type of security. This is something that WCF enhances quite significantly.
  • ASMX页面不会告诉您如何通过传输传递它以及使用特定类型的安全性。这是WCF非常显着的增强。

  • ASMX has a tight coupling with the HTTP runtime and the dependence on IIS to host it. WCF can be hosted by any Windows process that is able to host the .NET Framework 3.0.
  • ASMX与HTTP运行时紧密耦合,并依赖IIS来托管它。 WCF可由任何能够托管.NET Framework 3.0的Windows进程托管。

  • ASMX service is instantiated on a per-call basis, while WCF gives you flexibility by providing various instancing options such as Singleton, private session, per call.
  • ASMX服务基于每个呼叫进行实例化,而WCF通过提供各种实例化选项(如Singleton,私有会话,每次调用)为您提供灵活性。

  • ASMX provides the way for interoperability but it does not provide or guarantee end-to-end security or reliable communication.
  • ASMX提供了互操作性的方式,但它不提供或保证端到端的安全性或可靠的通信。

#2


WCF is far wider in scope than ASP.Net webservices.

WCF的范围远远超过ASP.Net webservices。

  • WCF can run in any application. APS.Net webservices only run in IIS.
  • WCF可以在任何应用程序中运行。 APS.Net webservices仅在IIS中运行。

  • WCF supports models like ReST, Remoting, SOAP, MSMQ etc. ASP.Net only supports SOAP
  • WCF支持ReST,Remoting,SOAP,MSMQ等模型.ASP.Net仅支持SOAP

  • WCF is more configurable.
  • WCF更易于配置。

  • WCF supports a more declarative way of programming. You can get more done with less code.
  • WCF支持更具说明性的编程方式。您可以使用更少的代码完成更多工作。

#3


ASP.NET Web Services are pretty much just that. Web Services. They're SOAP/WSDL based and provide their services only to the web.

ASP.NET Web服务就是这样。网页服务。它们基于SOAP / WSDL,仅向Web提供服务。

WCF Services offer a much more flexible framework. For instance, depending on how the service is defined, it can be a Web Service hosted in IIS which serialized its data via XML and uses the REST model...or it can be a Remote Windows Service that is hosted in it's own process and serializes its data via binary. All of this is achieved using the different Service/Data contracts in WCF.

WCF服务提供了更灵活的框架。例如,根据服务的定义方式,它可以是IIS中托管的Web服务,它通过XML序列化其数据并使用REST模型......或者它可以是托管在其自己的进程中的远程Windows服务,通过二进制序列化其数据。所有这些都是使用WCF中的不同服务/数据合同实现的。

In short...you can make a WCF service look almost identical to a .NET 2.0 Web Service fairly easily but, with a little work, you can do a WHOLE LOT MORE.

简而言之......您可以非常轻松地使WCF服务看起来几乎与.NET 2.0 Web服务相同,但是,通过一些工作,您可以做得更多。