Windows Communication Foundation (正體)
Windows Communication Foundation (WCF) 是由微软发展的一组数据通信的应用程序开发界面,它是.NET框架的一部分,由 .NET Framework 3.0 开始引入,与 Windows Presentation Foundation 及 Windows Workflow Foundation 并列为新一代 Windows 操作系统以及 WinFX 的三个重大应用程序开发类库。
在 .NET Framework 2.0 以及前版本中,微软发展了 Web Service (SOAP with HTTP communication),.NET Remoting (TCP/HTTP/Pipeline communication) 以及基础的 Winsock 等通信支持,由于各个通信方法的设计方法不同,而且彼此之间也有相互的重叠性(例如 .NET Remoting 可以开发 SOAP, HTTP 通信),对于开发人员来说,不同的选择会有不同的程序设计模型,而且必须要重新学习,让开发人员在用户有许多不便。同时,服务导向架构 (Service-Oriented Architecture) 也开始盛行于软件工业中,因此微软重新查看了这些通信方法,并设计了一个统一的程序开发模型,对于数据通信提供了最基本最有弹性的支持,这就是 Windows Communication Foundation。
目录 |
WCF 由于集合了几乎由 .NET Framework 所提供的通信方法,因此学习曲线比较陡峭,开发人员必须要针对各个部份的内涵做深入的了解,才能够操控 WCF 来开发应用程序。
WCF 的基本概念是以合约 (Contract) 来定义双方沟通的协议,合约必须要以界面的方式来体现,而实际的服务代码必须要由这些合约界面派生并实现。合约分成了四种:
一个 WCF 中的合约,就如同下列代码所示:
using System; using System.ServiceModel; namespace Microsoft.ServiceModel.Samples { [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")] // 服務合約 public interface ICalculator { [OperationContract] // 營運合約 double Add(double n1, double n2); [OperationContract] // 營運合約 double Subtract(double n1, double n2); [OperationContract] // 營運合約 double Multiply(double n1, double n2); [OperationContract] // 營運合約 double Divide(double n1, double n2); } }
由于 WCF 支持了 HTTP,TCP,Named Pipe,MSMQ,Peer-To-Peer TCP 等协议,而 HTTP 又分为基本 HTTP 支持 (BasicHttpBinding) 以及 WS-HTTP 支持 (WsHttpBinding),而 TCP 亦支持 NetTcpBinding,NetPeerTcpBinding 等通信方式,因此,双方必须要统一通信的协议,并且也要在编码以及格式上要有所一致。
一个设置通信协议绑定的示例如下:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <!-- 設定服務繫結的資訊 --> <services> <service name=" CalculatorService" > <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1" contract="ICalculator" /> </service> </services> <!-- 設定通訊協定繫結的資訊 --> <bindings> <wsHttpBinding> <binding name="Binding1"> </binding> </wsHttpBinding> </bindings> </system.serviceModel> </configuration>
虽然 WCF 也可以使用 SOAP 做通信格式,但它和以往的 ASP.NET XML Web Services 不同,因此有部份技术文章中,会将 ASP.NET 的 XML Web Services 称为 ASMX Service。
WCF 的服务可以挂载于 Console Application,Windows Application,IIS (ASP.NET) Application,Windows Service 以及 Windows Activation Services 中,但大多都会挂在 Windows Service。
WCF 实现上已经支持了传输层次安全性 (Transport-level security) 以及消息层次安全性 (Message-level security) 两种。
对于 WCF 的用户端来说,WCF 服务就像是一个 Web Service 一样,在 Visual Studio 2008 中,所有 WCF 服务的连接都是由用户端的 WCF Service Proxy 来运行,开发人员不用花费太多心思在通信上,而 WCF Service Proxy 在 Visual Studio 中被称为服务参考 (Service Reference)。
在 Visual Studio 中加入 WCF 的服务参考时,Visual Studio 会自动帮开发人员做掉一些必要工作(例如组态建立以及产生 Service Proxy 等),开发人员只需要在代码中取用 WCF Service Proxy 对象即可。
本文中的示例均来自 MSDN Library: WCF Portal 中。
|
查 • 论 • 编 • 历
|
|
|---|---|
| 图形界面 | 桌面窗口管理员 · DirectX · Direct3D · GDI · WPF · Windows色彩系统 · Windows Image Acquisition · Windows Imaging Component |
| 音乐与音效 | DirectSound · DirectMusic · DirectX外挂 · XACT · 语音API |
| 多媒体 | DirectShow · DirectX Media Objects · DirectX Video Acceleration · Windows Media · Media Foundation · Image Mastering API |
| Web | MSHTML · 微软XML剖析器 · RSS Platform · JScript · VBScript · 浏览器协助工具对象 · XMLHTTP · SideBar小工具 |
| 数据访问 | 数据访问元件集 · 延伸储存引擎 · ADO.NET · ADO.NET Entity Framework · ADO.NET Data Services · Microsoft Sync Framework · Jet数据库引擎 · OLE DB |
| 网络 | Winsock (LSP) · Winsock Kernel · Filtering Platform · 网络驱动程序界面规格(NDIS) · Windows Rally · 智能型背景传输服务 · Windows Vista 对等通信 API · Active Directory Service Interface |
| 通信 | 消息 API · 电话 API |
| 管理 | Win32 console · Windows Script Host · WMI · Windows PowerShell · 工作调度程序 · Offline Files · Shadow Copy · Windows Installer · Windows错误回报 · 事件记录器 · Common Log File System |
| 元件与模型 | COM · COM+ · ActiveX · Distributed COM · .NET Framework |
| 函数库 | MFC · ATL · WTL |
| 驱动程序开发 | Windows Driver Model (Broadcast Driver Architecture) · Windows Driver Foundation (KMDF · UMDF) |
| 安全性 | Crypto API (CAPICOM) · Windows CardSpace · Data Protection API · Security Support Provider Interface |
| .NET | .NET Framework · ASP.NET · ASP.NET AJAX · ADO.NET · Remoting · WPF · WF · WCF · Windows CardSpace · XNA · Silverlight · Task Parallel Library |
| 软件工厂 | EFx Factory · Enterprise Library · 复合用户界面 · CCF · CSF |
| 进程间通信 | MSRPC · 具名管道 · 存储器映射档 · 动态数据交换 · MailSlot |
| 可协助性 | Active Accessibility · 用户界面自动化 |
| 文字与多语系支持 | Text Services Framework · Text Object Model · 输入法编辑器 · 语言界面包 · 多语系用户界面 · Uniscribe |
| 游戏开发 | Direct3D · D3DX · DirectSound · DirectInput · DirectPlay · DirectMusic · Managed DirectX · Microsoft XNA |
|
查 • 论 • 编 • 历
|
|||||
|---|---|---|---|---|---|
| 架构 | 基类库 · 共同语言运行期元件 · 代码访问安全性 · 组件 · 元数据 · COM互通性 | ||||
| 共同语言基础架构 | 共同语言基础架构(CLI) · 共同型别系统 · 共同中介语言 · 虚拟运行系统 | ||||
| CLI 支持语言 |
|
||||
| 应用平台 | WPF · WCF · WF (WWF) | ||||
| 元件 | ADO.NET (Entity Framework · Data Services) · ASP.NET (AJAX · MVC · Dynamic Data) · Remoting · LINQ · Windows CardSpace · Windows Forms · XAML · ClickOnce · Dynamic Language Runtime · Parallel FX Library (PLINQ · TPL) | ||||
| 其他平台实现 | Mono · Compact Framework · Micro Framework · Portable.NET · Silverlight · SSCLI | ||||
| 比较 | C#与Java · C#与Visual Basic .NET · Java与.NET平台 | ||||
| 即将推出 | "Acropolis" · "Jasper" | ||||
| 1 这些语言都被包含在Visual Studio. 2 被多数用户使用,且非教学或研究型的语言。 |
|||||
stock | retire | vm
Why are we here?
All text is available under the terms of the GNU Free Documentation License
This page is cache of Wikipedia. History