"Basically, WCF is a service layer that allows you to build applications that can communicate using a variety of communication mechanisms. With it, you can communicate using Peer to Peer, Named Pipes, Web Services and so on.
您无法比较它们,因为 WCF 是用于构建可互操作应用程序的框架。如果您愿意,可以将其视为 SOA 实现者。这是什么意思?
WCF 符合 ABC,其中 A 是您想要通信的服务的地址,B 代表绑定,C 代表契约。这一点很重要,因为可以在不必更改代码的情况下更改绑定。契约的力量要强大得多,因为它迫使契约与实现分离。这意味着契约是在一个接口中定义的,并且有一个具体的实现,使用者使用相同的契约思想来约束这个实现。数据模型被抽象出来了。”
但是 WCF 支持比 ASP.NET Web 服务更多的消息传输协议。WCF 支持使用 HTTP、传输控制协议(TCP)、命名管道和微软消息队列(MSMQ)发送消息。
要在 Web 服务中开发服务,我们将编写以下代码
[WebService]
public class Service : System.Web.Services.WebService
{
[WebMethod]
public string Test(string strMsg)
{
return strMsg;
}
}
要在 WCF 中开发服务,我们将编写以下代码
[ServiceContract]
public interface ITest
{
[OperationContract]
string ShowMessage(string strMsg);
}
public class Service : ITest
{
public string ShowMessage(string strMsg)
{
return strMsg;
}
}
Web Service is not architecturally more robust. But WCF is architecturally
more robust and promotes best practices.
Web Services use XmlSerializer but WCF uses DataContractSerializer. Which is
better in performance as compared to XmlSerializer?
For internal (behind firewall) service-to-service calls we use the net:tcp
binding, which is much faster than SOAP.
WCF is 25%—50% faster than ASP.NET Web Services, and approximately 25%
faster than .NET Remoting.
When would I opt for one over the other?
WCF is used to communicate between other applications which has been developed on other platforms and using other Technology.
For example, if I have to transfer data from .net platform to other application which is running on other OS (like Unix or Linux) and they are using other transfer protocol (like WAS, or TCP) Then it is only possible to transfer data using WCF.
Here is no restriction of platform, transfer protocol of application while transferring the data between one application to other application.