📜  WCF和Web服务的区别

📅  最后修改于: 2021-09-13 02:04:25             🧑  作者: Mango

WCF(Windows Communication Foundation): WCF,顾名思义,是一个统一的.NET框架,用于开发面向服务的应用程序。它允许您开发可以使用不同通信机制进行通信的应用程序。它是为其他 Microsoft 分布式技术而建立的,并被认为是分布式计算的未来。由于其灵活性,它使端点的开发变得更加容易。它支持各种编程语言和平台。它基于 SOAP 并以 XML 格式返回数据。它可以托管在不同的场景中,此类场景包括各种服务,如WAS、IIS、Managed Windows等。以下代码将用于在WCF中构建服务:

[ServiceContract]  
public interface ITest  
{    
 [OperationContract]    
 string ShowMessage(string strMsg);  
}  
public class Service: ITest  
{    
 public string ShowMessage(string strMsg)    

Web Service: Web Service,顾名思义,是一种客户端-服务器应用程序,允许客户端和服务器应用程序之间进行通信。它基本上是一个专门设计用于执行特定任务集的软件模块。该服务专门用于使应用平台和技术独立。有两种类型的 Web 服务,包括 SOAP Web 服务和 RESTful Web 服务。以下代码将用于在 Web 服务中构建服务:

[WebService]  
public class Service: System.Web.Services.WebService  
{  
 [WebMethod]  
 public string Test(string strMsg)    
    {    return strMsg; 
    }  
}  

WCF 与 Web 服务

WCF  

Web Service 

It is used for sending data asynchronous messages from one service endpoint to another.   It is used to exchanging data between applications or systems.  
Protocols used in this channel include HTTP, TCP, MSMQ, named Pipers. Protocols used in the channel include HTTP and JMS.  
It is designed to offer a manageable approach for creating Web Services and Web service clients.   It is designed to perform or execute a certain set of tasks. 
It provides a runtime environment for service allowing you to expose CLR types as Services and to use other services as CLR types.  Service-oriented allows you to expose the functionality of existing code over the network so that other applications can consume the functionality of your program.  
Its features include service-oriented, reliable, and queued messages, multiple transports, and encoding that support multiple message patterns, interoperability, etc.   Its features include loosely coupled, supports document exchange, supports RCF (Remote Procedure Calls), ability to be Synchronous or Asynchronous, language-independent and interoperable, etc.  
It is more flexible as this service can be hosted in different types of applications.   It is less flexible as it can only be accessed over HTTP.  
Such service can be hosted on IIS, WAS, and Windows services.   Such a service can only be hosted on IIS server.  
It uses DataContractSerializer.   It uses XmlSerializer.  
Its extension is “.svc”.   Its extension is “.asmx”. 
It is more reliable, fast, and robust as compared to web services, and therefore it considered good for developing real-time applications.   It is not reliable and slow as compared to WCF.  
It supports duplex operations and multi-threading.   It does not support duplex operations and multi-threading.  
It also supports robust security, trustworthy messaging, transaction. It only supports security services.