First of all, it needs to understand that WCF Service provides all the capabilities of .NET web servies and further extends it.
首先需要了解的是,WCF服务提供了.net web 服务的所有功能,并且对其有所扩展。
Simple and basic difference is that ASMX web service is designed to send and receive messages using SOAP over HTTP only. While WCF service can exchange messages using any format (SOAP is default) over any transport protocol (HTTP, TCP/IP, MSMQ, NamedPipes etc).
ASMX Web服务用于使用HTTP协议进行SOAP消息的接收和发送而设计。但是WCF服务则可以使用任何消息格式(SOAP默认),任何传输协议进行数据交互(HTTP,TCP/IP,MSMQ,命名管道等)。
ASMX is simple but limited in many ways as compared to WCF.
ASMX很简单但是和WCF比起来,却存在诸多限制。
1.ASMX web services can be hosted only in IIS while WCF service has all the following hosting options:
a. IIS
b. WAS (Windows Process Activation Services)
c. Console Application
d. Windows NT Services
e. WCF provided Host
1.ASMX Web服务只能够被IIS寄宿,但是WCF服务却可以有如下的寄宿方式:
a.IIS
b.WAS(Windows Process Activation Services Windows进程激活服务)
c.控制台程序
d.Windows NT服务
e.WCF自寄宿
2.ASMX web services support is limited to HTTP while WCF supports HTTP, TCP, MSMQ, NamedPipes.
2.ASMX web服务只能支持HTTP传输,但是WCF支持HTTP,TCP,MSMQ,命名管道。
3.ASMX Security is limited. Normally authentication and authorization is done using IIS and ASP.NET security configuration and transport layer security.For message layer security, WSE can be used.
WCF provides a consistent security programming model for any protocol and it supports many of the same capabilities as IIS and WS-* security protocols, additionally, it provides support for claim-based authorization that provides finer-grained control over resources than role-based security.WCF security is consistent regardless of the host that is used to implement WCF service.
3.ASMX在安全控制方面功能有限,包括普通的验证,基于IIS的验证,Asp.net安全配置,传输层安全控制。对于应用层安全来说,可以使用WSE来进行。
WCF则为所有的传输协议提供一致的安全验证模块,同时它支持类似于IIS和WS-*的安全协议,此外,它还支持提供比role-based更加细粒度的针对资源操控的Claim-based验证. WCF安全验证和寄宿主体无关。
4.Another major difference is that ASMX web services uses XmlSerializer for serialization while WCF uses DataContractSerializer which is far better in performance than XmlSerializer.
Key Issues with XmlSerializer in serializing .NET types to xml are:
a. Only public fields or properties of the .NET types can be translated to Xml.
b. Only the classes that implement IEnumerable can be translated.
c. Classes that implement IDictionary, such as Hashtable cannot be serialized.
4.另外一个主要的区别是,ASMX Web服务使用XmlSerializer进行序列化,但是WCF使用DataContractSerializer。后者在性能上完爆。
对于XmlSerializer进行.NET类型序列化来说,问题有以下几点:
a.只有PUBLIC字段或者属性才能够被转换成xml
b.只有实现了IEnumerable接口的类才能够被转化。
c.只有实现了IDictionary的类才能够被转化。比如说HashTable