Interoperability[edit]
WCF supports interoperability with WCF applications running on the same Windows machine or WCF running on a different Windows machines or standard Web services built on platforms such as Java running on Windows or other operating systems. In addition to SOAP, WCF 4 supports non-SOAP XML, RSS, JSON, and binary formats for external communication via HTTP or HTTPS.[6]
WCF Integration with Other Microsoft Technologies
WCF is a flexible platform. Because of this extreme flexibility, WCF is also used in several other Microsoft products. By understanding the basics of WCF, you have an immediate advantage if you also use any of these products.
The first technology to pair with WCF was the Windows Workflow Foundation (WF). Workflows simplify application development by encapsulating steps in the workflow as “activities.” In the first version of Windows Workflow Foundation, a developer had to create a host for the workflow. The next version of Windows Workflow Foundation was integrated with WCF. That allowed any workflow to be easily hosted in a WCF service. You can do this by automatically choosing the WF/WCF project type in Visual Studio 2012 or later.
Microsoft BizTalk Server R2 also utilizes WCF as a communication technology. BizTalk is designed to receive and transform data from one standardized format to another. Messages must be delivered to its central message box where the message can be transformed using either a strict mapping or by using one of the BizTalk features such as its workflow engine. BizTalk can now use the WCF Line of Business (LOB) adapter to deliver messages to the message box.
The hosting features of Windows Server AppFabric application server are specifically designed for deploying and managing applications that use WCF for communication. The hosting features include rich tooling and configuration options specifically designed for WCF-enabled applications.
Develop Service-Oriented Applications with WCF
This section of the documentation provides information about Windows Communication Foundation (WCF), which is a unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing investments.
gRPC as an alternative to WCF
gRPC is a modern RPC framework that is a popular alternative to WCF. gRPC is built on top of HTTP/2, which provides a number of advantages over WCF, including:
- Performance: gRPC is much more efficient than WCF, especially for long-running connections.
- Scalability: gRPC is designed to scale to large numbers of clients and servers.
- Security: gRPC supports a variety of security mechanisms, including TLS and authentication.
- Cross-platform: gRPC is platform-neutral and can be used with a variety of programming languages.
For more information on developing or migrating WCF apps to gRPC, see:
- Why we recommend gRPC for WCF developers
- Comparing WCF to gRPC
- Introduction to gRPC for WCF developers
What Is Windows Communication Foundation
Windows Communication Foundation (WCF) is a framework for building service-oriented applications. Using WCF, you can send data as asynchronous messages from one service endpoint to another. A service endpoint can be part of a continuously available service hosted by IIS, or it can be a service hosted in an application. An endpoint can be a client of a service that requests data from a service endpoint. The messages can be as simple as a single character or word sent as XML, or as complex as a stream of binary data. A few sample scenarios include:
-
A secure service to process business transactions.
-
A service that supplies current data to others, such as a traffic report or other monitoring service.
-
A chat service that allows two people to communicate or exchange data in real time.
-
A dashboard application that polls one or more services for data and presents it in a logical presentation.
-
Exposing a workflow implemented using Windows Workflow Foundation as a WCF service.
While creating such applications was possible prior to the existence of WCF, WCF makes the development of endpoints easier than ever. In summary, WCF is designed to offer a manageable approach to creating Web services and Web service clients.
The architecture[edit]
WCF is a tool often used to implement and deploy a service-oriented architecture (SOA). It is designed using service-oriented architecture principles to support distributed computing where services have remote consumers. Clients can consume multiple services; services can be consumed by multiple clients. Services are loosely coupled to each other. Services typically have a WSDL interface (Web Services Description Language) that any WCF client can use to consume the service, regardless of which platform the service is hosted on. WCF implements many advanced Web services (WS) standards such as WS-Addressing, WS-ReliableMessaging and WS-Security. With the release of .NET Framework 4.0, WCF also provides RSS Syndication Services, WS-Discovery, routing and better support for REST services.
Endpoints[edit]
A WCF client connects to a WCF service via an endpoint. Each service exposes its contract via one or more endpoints. An endpoint has an address (which is a URL specifying where the endpoint can be accessed) and binding properties that specify how the data will be transferred.
The mnemonic “ABC” can be used to remember address/binding/contract. Binding specifies what communication protocols are used to access the service, whether security mechanisms are to be used, and the like. WCF includes predefined bindings for most common communication protocols such as SOAP over HTTP, SOAP over TCP, and SOAP over Message Queues, etc. Interaction between WCF endpoint and client is done using a SOAP envelope. SOAP envelopes are in simple XML form, which makes WCF platform-independent. When a client wants to access the service via an endpoint, it not only needs to know the contract, but it also has to adhere to the binding specified by the endpoint. Thus, both client and server must have compatible endpoints.
With the release of the .NET Framework 3.5 in November 2007, Microsoft released an encoder that added support for the JSON serialization format to WCF.[4]
Behaviors[edit]
Behaviors are types that modify or extend service or client functionality. Behaviors allow the developer to create custom processing, transformation, or inspection that is applied to messages as they are sent or received. Some examples of uses for behaviors are:
- Controlling whether metadata is published with a service.
- Adding security features to a service, such as impersonation, authorization,[5] or managing tokens
- Recording information about messages, such as tracking, tracing, or logging
- Message or parameter validation
- Invoking all additional operations when messages are received—such as notifying users when certain messages arrive
Behaviors implement the
IServiceBehavior
interface for service extensions, the
IEndpointBehavior
for endpoints, the
IContractBehavior
interface for service contracts, or the
IOperationBehavior
for operations. Service behaviors are used for message processing across a service, rather than processing that would be specific to a single operation.
Features of WCF
WCF includes the following set of features. For more information, see WCF Feature Details.
-
Service Orientation
One consequence of using WS standards is that WCF enables you to create service oriented applications. Service-oriented architecture (SOA) is the reliance on Web services to send and receive data. The services have the general advantage of being loosely-coupled instead of hard-coded from one application to another. A loosely-coupled relationship implies that any client created on any platform can connect to any service as long as the essential contracts are met.
-
Interoperability
WCF implements modern industry standards for Web service interoperability. For more information about the supported standards, see Interoperability and Integration.
-
Multiple Message Patterns
Messages are exchanged in one of several patterns. The most common pattern is the request/reply pattern, where one endpoint requests data from a second endpoint. The second endpoint replies. There are other patterns such as a one-way message in which a single endpoint sends a message without any expectation of a reply. A more complex pattern is the duplex exchange pattern where two endpoints establish a connection and send data back and forth, similar to an instant messaging program. For more information about how to implement different message exchange patterns using WCF see Contracts.
-
Service Metadata
WCF supports publishing service metadata using formats specified in industry standards such as WSDL, XML Schema and WS-Policy. This metadata can be used to automatically generate and configure clients for accessing WCF services. Metadata can be published over HTTP and HTTPS or using the Web Service Metadata Exchange standard. For more information, see Metadata.
-
Data Contracts
Because WCF is built using the .NET Framework, it also includes code-friendly methods of supplying the contracts you want to enforce. One of the universal types of contracts is the data contract. In essence, as you code your service using Visual C# or Visual Basic, the easiest way to handle data is by creating classes that represent a data entity with properties that belong to the data entity. WCF includes a comprehensive system for working with data in this easy manner. Once you have created the classes that represent data, your service automatically generates the metadata that allows clients to comply with the data types you have designed. For more information, see Using Data Contracts.
-
Security
Messages can be encrypted to protect privacy and you can require users to authenticate themselves before being allowed to receive messages. Security can be implemented using well-known standards such as SSL or WS-SecureConversation. For more information, see Security.
-
Multiple Transports and Encodings
Messages can be sent on any of several built-in transport protocols and encodings. The most common protocol and encoding is to send text encoded SOAP messages using the HyperText Transfer Protocol (HTTP) for use on the World Wide Web. Alternatively, WCF allows you to send messages over TCP, named pipes, or MSMQ. These messages can be encoded as text or using an optimized binary format. Binary data can be sent efficiently using the MTOM standard. If none of the provided transports or encodings suit your needs you can create your own custom transport or encoding. For more information about transports and encodings supported by WCF see Transports.
-
Reliable and Queued Messages
WCF supports reliable message exchange using reliable sessions implemented over WS-Reliable Messaging and using MSMQ. For more information about reliable and queued messaging support in WCF see Queues and Reliable Sessions.
-
Durable Messages
A durable message is one that is never lost due to a disruption in the communication. The messages in a durable message pattern are always saved to a database. If a disruption occurs, the database allows you to resume the message exchange when the connection is restored. You can also create a durable message using the Windows Workflow Foundation (WF). For more information, see Workflow Services.
-
Transactions
WCF also supports transactions using one of three transaction models: WS-AtomicTransactions, the APIs in the System.Transactions namespace, and Microsoft Distributed Transaction Coordinator. For more information about transaction support in WCF see Transactions.
-
AJAX and REST Support
REST is an example of an evolving Web 2.0 technology. WCF can be configured to process “plain” XML data that is not wrapped in a SOAP envelope. WCF can also be extended to support specific XML formats, such as ATOM (a popular RSS standard), and even non-XML formats, such as JavaScript Object Notation (JSON).
-
Extensibility
The WCF architecture has a number of extensibility points. If extra capability is required, there are a number of entry points that allow you to customize the behavior of a service. For more information about available extensibility points see Extending WCF.
References[edit]
- ^ Michele Leroux Bustamante. “Hosting WCF Services”. CODE Magazine.
- ^ “Deploying an Internet Information Services-Hosted WCF Service”. Microsoft Developer Network (MSDN). 15 September 2021.
- ^ “CoreWCF 1.0 has been Released, WCF for .NET Core and .NET 5+”. .NET Blog. 2022-04-28. Retrieved 2022-06-06.
- ^ “AJAX Integration and JSON Support”. Microsoft. Retrieved 2008-04-24.
- ^ “Custom Authentication and Authorization in WCF”. TatvaSoft UK. Retrieved 2018-11-14.
- ^ “Introducing Windows Communication Foundation in .NET Framework 4”. Microsoft. Retrieved 2011-07-17.
- “What Is Windows Communication Foundation”. MSDN. Microsoft. 10 August 2023.
- “Windows Communication Foundation Architecture”. MSDN. Microsoft. 15 September 2021.
Hướng dẫn sử dụng WCF Service với C# – Sử dụng WCF Serivce
Bước 1: Tạo Console Application
Mở Visual Studio, tạo một project dạng Console Application và đặt tên CADemo
Bước 2: Thêm Service
Chuột phải lên References -> chọn Add Service Reference…
Nhập http://localhost/WcfServiceDemo/CalService.svc tại Address, chọn Go và nhập ServiceReferenceDemo tại Namespace
Bước 3: Mở Program.cs và thêm đoạn code sau
Bước 4: Chạy ứng dụng
Để chạy ứng dụng, chúng ta nhấn Ctrl + F5. Trong hình số 579 là tổng của 123 và 456
ngày 15-03-2016
Windows Communication Foundation (WCF) | ASP.NET Web Service |
Hỗ trợ được tất cả giao thức: HTTP, HTTPs, WSHTTP, TCP, MSMQ | Chỉ hỗ trợ giao thức HTTP, HTTPs |
Hỗ trợ đảm bảo giao tác an toàn – Atomic Transactions | Không hỗ trợ đảm bảo giao tác an toàn – Atomic Transactions |
Mặc định WCF sử dụng chuẩn SOAP để gửi và nhận thông điệp, nhưng WCF có thể hỗ trợ nhiều định dạng thông điệp khác nhau như: binary, MTOM (Message Transfer Optimized Mechanism),… | Chỉ có thể gửi và nhận thông điệp dạng chuẩn SOAP. |
Thông qua DataContractSerializer, có thể xác định thuộc tính nào, thể hiện nào cần chuyển đổi sang XML | Sử dụng XmlSerializer để chuyển đổi với nhiều hạn chế như chỉ có thuộc tính kiểu Public hay class dẫn xuất từ IEnumerablemới chuyển được. |
- WCF Tutorial
- WCF – Home
- WCF – Overview
- WCF – Versus Web Service
- WCF – Developers Tools
- WCF – Architecture
- WCF – Creating WCF Service
- WCF – Hosting WCF Service
- WCS – IIS Hosting
- WCF – Self-Hosting
- WCF – WAS Hosting
- WCF – Windows Service Hosting
- WCF – Consuming WCF Service
- WCF – Service Binding
- WCF – Instance Management
- WCF – Transactions
- WCF – RIA Services
- WCF – Security
- WCF – Exception Handling
- WCF Resources
- WCF – Quick Guide
- WCF – Useful Resources
- WCF – Discussion
WCF Tutorial
WCF stands for Windows Communication Foundation. It is a framework for building, configuring, and deploying network-distributed services. Earlier known as Indigo, it enables hosting services in any type of operating system process. This tutorial explains the fundamentals of WCF and is conveniently divided into various sections. Every section of this tutorial has adequate number of examples to explain different concepts of WCF.
Audience
The objective of this tutorial is to help those readers who want to learn the basics of WCF from scratch. After completing this tutorial, the readers will acquire sufficient knowledge on WCF and advance to a higher level of expertise.
Prerequisites
Anyone having a basic understanding of the .NET framework can use this tutorial to learn WCF. Prior awareness of web services will help pick up the concepts faster.
WCF (Windows Communication Foundation):– Cấu trúc của WCF service.– Mô hình kết nối ABC.– Các loại Contract.
Khái niệm
“Windows Communication Foundation (WCF) is Microsoft’s unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing investments.” (MSDN).
WCF (Windows Communication Foundation) là công nghệ mới nhất được thiết kế theo kiến trúc hướng dịch vụ (Service Oriented Architecture – SOA). Mục đích của WCF là tạo một công nghệ thống nhất cho các công nghệ giao tiếp trước đây như: Web Services, .NET Remoting, Microsoft Message Queuing và COM+.
Ba thành phần chính của một WCF service là:
– Service class: định nghĩa các contact (sẽ trình bày ở bên dưới).
– Hosting environment: WCF service có thể được host lên nhiều “môi trường” khác nhau, bao gồm IIS, Windows service, Selt-hosting.
– End point: Các “cổng” kết nối giữa client và service.
Mô hình kết nối ABC
Việc giao tiếp giữa client và WCF service được thực hiện thông qua các Endpoint. Như vậy một service có thể làm chấp nhận và xử lý nhiều yêu cầu khác nhau thông các endpoint riêng biệt. Mỗi endpoint được tạo thành từ ba thành phần với tên gọi tắt rất dễ nhớ là ABC. Trong đó:
– A – Address (Where): địa chỉ của service.
– B – Binding (How): Cách thức giao tiếp với service. Thành phần này xác định loại giao thức kết nối giữa client và service (như HTTP, TCP, MSMQ,…), kênh xử lý và kiểu mã hóa thông điệp. Danh sách các kiểu binding:
Name | Purpose |
BasicHttpBinding | Interoperability with Web services and clients supporting the WS-BasicProfile 1.1 and Basic Security Profile 1.0. |
WSHttpBinding | Interoperability with Web services and clients that support the WS-* protocols over HTTP. |
WSDualHttpBinding | Duplex HTTP communication, by which the receiver of an initial message does not reply directly to the initial sender, but may transmit any number of responses over a period of time by using HTTP in conformity with WS-* protocols. |
WSFederationBinding | HTTP communication, in which access to the resources of a service can be controlled based on credentials issued by an explicitly-identified credential provider. |
NetTcpBinding | Secure, reliable, high-performance communication between WCF software entities across a network. |
NetNamedPipeBinding | Secure, reliable, high-performance communication between WCF software entities on the same machine. |
NetMsmqBinding | Communication between WCF software entities by using MSMQ. |
MsmqIntegrationBinding | Communication between a WCF software entity and another software entity by using MSMQ. |
NetPeerTcpBinding | Communication between WCF software entities by using Windows Peer-to-Peer Networking. |
– C – Contact (What): Bản mô tả các chức năng của service. Cụ thể, đây là các class (structure, enum,…) được định nghĩa bên service để với các phương thức mà client có thể yêu cầu service thực hiện.
Contract
Contract được coi là một bản “hợp đồng” quy định cách thức và phương tiện để hai bên có thể hợp tác và làm việc với nhau. Trong WCF, các contact được coi như những bản mô tả nhiệm vụ, kiểu dữ liệu của service. Client sẽ có được các contact sau khi tham chiếu đến service và thông qua đó để gửi và nhận các thông điệp. Như vậy, service và client không sử dụng cùng các kiểu dữ liệu như nhau, mà chỉ sử dụng chung các contact.
Service Contract
Mô tả các công việc của service, bao gồm các kiểu dữ liệu truyền đi và kiểu dữ liệu trả về. Cụ thể, đây là các khai báo phương thức kèm với các tham số và kiểu trả về của service. Loại contract này có thể được chia ra làm hai phần là service contract (tương ứng với các interface) và operation contract (là các method).
Data Contract
“A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged. That is, to communicate, the client and the service do not have to share the same types, only the same data contracts. A data contract precisely defines, for each parameter or return type, what data is serialized (turned into XML) to be exchanged.” (MSDN)
Mô tả các kiểu dữ liệu tự tạo mà client có thể sử dụng. Các contract này dùng để chứa các dữ liệu cần thiết để truyền tải giữa client và service. Nếu service chỉ sử dụng các kiểu dữ liệu đơn giản (như int, string, DateTime,…) thì service đó không cần đến Data Contract.
Message Contract
Tương tự như Data Contract nhưng kiểu contract này nhằm mục đích định nghĩa cấu trúc của các thông điệp được truyền tải dưới dạng SOAP (Simple Object Access Protocol). Một thông điệp SOAP được chia thành 2 phần là header và body.
MSDN – Mối quan hệ của các loại contract với với common language runtime (CLR)
Fault Contract
Loại contact này giúp quản lý các ngoại lệ mà service ném ra khi thực hiện các yêu cầu của client. Khi cần thiết, service sẽ ném ra một FaultException nếu như muốn client bắt được ngoại lệ này.
Tham khảo
Fundamental Windows Communication Foundation Concepts (http://msdn.microsoft.com/en-us/library/ms731079.aspx)
Windows Communication Foundation (http://msdn.microsoft.com/en-us/library/ms735119(v=vs.90).aspx)
Windows Communication Foundation FAQ (http://www.codeproject.com/Articles/29475/Windows-Communication-Foundation-FAQ-quick-starter)
YinYang’s Programming Blog
An Introduction to WCF: Windows Communication Foundation
Windows Communication Foundation (WCF) is a framework by Microsoft for building service-oriented applications on the .NET platform. In this comprehensive guide, we will take a look at the basics of WCF, the problems it solves, features, architecture, and how to build WCF services and clients.
Understanding Service-Oriented Architecture
Before diving into WCF, it’s important to understand Service-Oriented Architecture (SOA), which provides the foundation for WCF services.
SOA is an architectural approach for building distributed systems as modular services that can be easily consumed and reused. These services have the following characteristics:
SOA enables building complex, scalable and distributed applications by composing loosely coupled services across platforms and organizations. Now let’s see how WCF enables building SOA solutions on .NET.
Need for WCF
Earlier Microsoft provided various technologies for building services like ASP.NET Web Services (ASMX), .NET Remoting, Enterprise Services etc. However, these existed as independent siloed technologies making it hard to build complete solutions.
WCF unified all these into a single service development framework with the following goals:
WCF provides a comprehensive approach to implement SOA principles for building distributed and decoupled system.
Key Concepts of WCF
Some key concepts to understand in WCF:
SOAP and REST
WCF services can be exposed over SOAP (Simple Object Access Protocol) or REST (Representational State Transfer) endpoints. SOAP involves exchanging XML messages while REST uses plain HTTP requests.
Message Exchange Patterns
WCF supports various message exchange patterns like one-way (fire and forget), request-reply, duplex (two-way) communication.
Endpoints
Endpoints represent a distinct addressable point where a service can be accessed using a specific protocol/data format combination. Services can expose multiple endpoints.
Addresses, Bindings and Contracts
These constitute the “ABC” of WCF:
These three components fully describe a service endpoint in WCF.
Hosting
WCF services need to be hosted in a host process like a console app, Windows service, or IIS to be consumable. The host initializes and makes the service available. These key concepts make up the core of WCF architecture and programming model.
WCF Architecture and Components
WCF is designed based on SOA principles and contains the following key components:
These components allow creating and exposing services independently of the underlying implementation and communication mechanisms.
Defining Service Contracts
Service contracts define what service operations a client can perform. These are defined as .NET interfaces with attributes as follows:
[ServiceContract]
public interface ICustomerService
[OperationContract]
Customer GetCustomer(int id);
[OperationContract]
void UpdateCustomer(Customer customer);
A service implementing this interface must define these methods. Multiple interfaces can be combined to expose a larger contract.
Defining Data Contracts
Data contracts define the data types used in service operations. These are regular .NET classes annotated as:
[DataContract]
public class Customer
[DataMember]
public int ID { get; set; }
[DataMember]
public string Name { get; set; }
Data contracts maximize interoperability across platforms.
Service and Data Contract Separation
A key benefit of separating service and data contracts is that they can evolve independently. Service contract being an interface remains unchanged while data contract can add new properties without requiring service modification.
This separation hence allows independent evolution and maintainability.
Implementing Service Contract
To implement a WCF service, we create a class deriving from System.ServiceModel.ServiceBase and implementing the contract interface:
[ServiceBehavior(Namespace=”http://microsoft.com/customerservice”)]
public class CustomerService : ServiceBase, ICustomerService
// Implement contract methods
Service and data contracts are hence decoupled from implementation.
Hosting WCF Services
For clients to discover and consume the service, it needs to be hosted in a host process. WCF provides various hosting options:
IIS Hosting
Internet Information Services (IIS) provides built-in hosting capabilities for WCF services. Services are hosted in WAS (Windows Process Activation Service) processes.
Self-Hosting
WCF service can self-host in a custom Windows service or console app. This allows full control but extra effort.
Windows Process Activation Service (WAS)
In addition to IIS, WAS enables hosting WCF services in other processes like Windows services. Useful for services not exposed over HTTP. Proper hosting environment enables optimal stability, scalability and manageability of services.
Exposing Endpoints
A key WCF concept is endpoints which are a combination of address, binding and contract that specify how a service can be accessed.
For example, the same service can expose:
This enables exposing services optimally for diverse audiences. Endpoint configuration is done at hosting time.
Consuming WCF Services
To consume a WCF service, there are two approaches:
Channel Factory + Channel
This involves manually creating a channel factory for the endpoint, constructing a channel and invoking service operations. More code but full control.
Service Reference
Visual Studio can automatically generate strongly typed proxy classes for the service contract by adding a service reference. Simple usage but limited flexibility. Either way, the client only deals with the service contract, shielding implementation details.
Service Metadata and Discovery
For clients to easily discover and consume WCF services, services expose metadata using standard protocols:
WSDL
Web Service Description Language (WSDL) provides metadata like service endpoint details, operations, message formats etc. WCF can generate WSDL automatically.
WS-Metadata Exchange
Provides dynamic querying of metadata from service endpoint. Supports GET requests for metadata.
UDDI
Universal Description, Discovery and Integration (UDDI) defines service registries where services can publish metadata to be easily found. Using open standards for metadata and discovery helps make services accessible across platforms and frameworks.
Security
WCF network operations depend on security. Make sure that all data is encrypted, authenticated, and authorized. For a stable deployment, hire .NET developers who are conversant with WCF security features.
Transactions
WCF integrates seamlessly with underlying transaction frameworks like System.Transactions and MSDTC to make services transactional:
Transactions enable building robust services that safeguard data integrity.
Reliability and Availability
For mission-critical services, WCF provides reliability patterns like:
These constructs harden services for 24/7 production use under load.
Performance and Scalability
WCF includes optimization features for building high-performance services:
These allow smoothly scaling services across user load and data volumes.
WCF vs Web API
WCF provides a general framework for building services on .NET. For building HTTP REST services, Web API provides a more streamlined, REST-optimized experience.
Key differences:
So, in summary, Web API is best for public REST services while WCF provides full breadth across transport protocols.
Conclusion
WCF provides a comprehensive service-oriented framework for building distributed, interoperable and secure applications on the .NET platform. Its flexibility across protocols, robust security, transactions and reliability makes it a great choice for both internal and external enterprise SOA applications. For public HTTP REST services, Web API offers a simpler programming model. Understanding when to adopt WCF vs Web API based on the kinds of services required is important. But both continue to be crucial frameworks for .NET services. With Microsoft adding ongoing improvements in newer versions, WCF remains an indispensable part of enterprise .NET architecture.
WCF stands for Windows Communication Foundation. It is basically used to create a distributed and interoperable Application. WCF Applications came into the picture in .Net 3.0 Framework. This is a framework, which is used for creating Service oriented Applications. You can send the data asynchronously from one end point to another. I think you all know about Web Service and are thinking, if we already have Web Services and accessing on a remote basis then why did WCF come into picture?
There are so many reasons for it but now I am giving you an answer in two words- one is protocol and the other is hosting. Thus, I will explain these two words later in this article.
Distributed Application It means those Applications, which do not run only on
single system but can run on multiple systems, which are connected over the network. For example, a Web Service that can consume by different clients.
Interoperable
It means that an Application can consume or connect with another Application but it does not matter in which platform it is developed.
Example
Web Service is interoperable because it can be consume from any client,
either it is from Java or .NET but on a remote basis, it is not interoperable because if we
want to consume any remote service from the client, client Application must be
developed in .NET.
Why we need WCF Applications
In this, I am explaining why we need WCF Application, if we already have Web Service.
Suppose, you have two clients- one wants to use a Web Service, which sends data over
the network, using Http protocol and want reply in XML format, so we will create a Web Service.The other wants to send the data, using Web Service over the network, using TCP protocol
and replying in binary format, then we need to implement a remote Web service with
TCP protocol.
Problem
The problem is in the example, shown above, we need to create two different Services
for two different clients .WCF is solving this problem and one single service can
be consumed by two different clients- either they want same protocol or a different
protocol. We specify the protocol name in an endpoint attribute of the Web Service.
WCF
There are three parts of WCF Application or we can say it consists of three
things, which are-
- WCF Service : What is the service and what it is providing.
- WCF Service host: Where is the Service hosted.
- Service Client: Who is the client of the Service.
Fundamentals of WCF
Message
Message is the communication unit, as it is in the form of an envelop. The transmission of the data from the client to Service and Service to client is being done by envelop. The envelop or message has the sections, given below-
By default Header and fault are disabled but Body is responsible for the data transmission or data exchanging.
Header is useful to send some data from client to Server. Suppose we want to send user name from each request but don’t want to send it by an argument, we can easily add it into message header.
Endpoint
Endpoint is a very essential part of WCF Application, as it describes the address of Web Service from where a user can receive and send the message. It also specifies the communication mechanism of how the message will be sent or received.
End point consists of three things, which are A,B,C and
each of them have a question mark.
- Address (Where?)
- Binding (how?)
- Contract (What?)
Endpoint = A + B+ C Address is the address of WCF Service, where the Service is hosted? It gives the exact URL of Web Service, where the Service hosts the pattern of URL, which is- Scheme://domain/[:port]/path net.tcp://localhost:1234/MyService http://localhost:1234/MyService Binding
It describes the way or mechanism by which the user will communicate with Web Service. It constitutes some binding element, which creates the structure of communication such as some transport protocols like HTTP, TCP etc. Message format or security techniques etc. Contract
Contract is the third important question. What functionality and operation is being provided by the service is called contract. It specifies what functionality and operations are need to be exposed to the client. It is the interface name which has all operation that need to be exposed.
Hosting
Hosting is the important thing in WCF Application and it makes WCF Application different from other distributed Applications. WCF supports following types of hosting-
- IIS Hosting
- Self hosting
- WAS hosting
SOAP
SOAP stands for Simple Object Access Protocol. It is not a transport protocol but an XML based message protocol.
External links[edit]
- Windows Communication Foundation, MSDN Windows Communication Foundation portal.
- MSDN Library: Windows Communication Foundation
- WCF Security Guide Archived 2011-03-14 at the Wayback Machine, Microsoft Patterns & Practices – Improving Web Services Security: Scenarios and Implementation Guidance for WCF. Released Aug 1, 2008.
- Understanding WCF Services in Silverlight 2 Archived 2011-03-12 at the Wayback Machine – In depth explanation of WCF services for Silverlight clients.
- David Chappell: “Introduction to WCF” and “Dealing with Diversity”, two papers covering WCF. November 2007.
- Getting Started with WCF RIA Services – part 1 of the series articles on WCF RIA Services
- .NET terminology
- Windows communication and services
- Formerly proprietary software
- Free and open-source software
- Microsoft application programming interfaces
- Microsoft free software
- Object request broker
- Software using the MIT license
- Windows Server 2008
- Windows Vista
- Web services
- Service-oriented architecture-related products
- 2006 software
WCF viết tắt của Windows Communication Foundation. Nó là một phương pháp giúp các lập trình viên phát triển những ứng dụng hướng dịch vụ. Để hiểu rõ hơn về vấn đề này, các bạn hãy xem bài viết hướng dẫn sử dụng WCF Service với C#.
Trong bài viết này, chúng tôi sẽ hướng dẫn các bạn cách tạo WCF Service, triển khai WCF Service trên IIS và sử dụng WCF Service tại Client cài đặt bằng C#.
In this section
What’s New in Windows Communication Foundation 4.5Discusses features new to Windows Communication Foundation.
WCF Simplification FeaturesDiscusses new features that make writing WCF applications simpler.
Guide to the DocumentationA description of the WCF documentation
Conceptual OverviewSummarizes information about the Windows Communication Foundation (WCF) messaging system and the classes that support its use.
Getting Started TutorialA step by step tutorial to create a WCF service and client
Basic WCF ProgrammingDescribes the fundamentals for creating Windows Communication Foundation applications.
WCF Feature DetailsShows topics that let you choose which WCF feature or features you need to employ.
Extending WCFDescribes how to modify and extend WCF runtime components
Guidelines and Best PracticesProvides guidelines for creating Windows Communication Foundation (WCF) applications.
Administration and DiagnosticsDescribes the diagnostic features of WCF
Operating System Resources Required by WCFDescribes operating system resources required by WCF
Troubleshooting Setup IssuesProvides guidance for fixing WCF setup issues
Migrating from .NET Remoting to WCFCompares .NET Remoting to WCF and provides migration guidance for common scenarios.
Using the WCF Development ToolsDescribes the Visual Studio Windows Communication Foundation development tools that can assist you in developing your WCFservice.
Windows Communication Foundation ToolsDescribes WCF tools designed to make it easier to create, deploy, and manage WCF applications
Windows Communication Foundation SamplesSamples that provide instruction on various aspects of Windows Communication Foundation
Windows Communication Foundation GlossaryShows a list of terms specific to WCF
General ReferenceThe section describes the elements that are used to configure Windows Communication Foundation clients and services.
Privacy InformationInformation regarding WCF and Privacy
Windows Communication Foundation
Original author(s) | Microsoft |
Developer(s) | .NET Foundation |
Initial release | November 21, 2006 |
Stable release |
v3.4.0 / August 18, 2022 |
Repository | github |
Written in | C# |
Operating system | Linux, macOS, Windows |
Platform | .NET Framework, .NET |
Predecessor | Web Services Enhancements |
Type | Software framework |
License | MIT License |
Website | docs |
The Windows Communication Foundation (WCF), previously known as Indigo, is a free and open-source runtime and a set of APIs in the .NET Framework for building connected, service-oriented applications.[1][2]
.NET Core 1.0, released 2016, did not support WCF server side code. WCF support was added to the platform with support for .NET Core 3.1, .NET 5, and .NET 6 in 2022.[3]
Further reading[edit]
- Craig McMurtry, Marc Mercuri, and Nigel Watling: Microsoft Windows Communication Foundation: Hands-On, SAMS Publishing, May 26, 2004, ISBN 0-672-32877-1
- Steve Resnick, Richard Crane, Chris Bowen: Essential Windows Communication Foundation (WCF): For .NET Framework 3.5, Addison-Wesley, February 11, 2008, ISBN 0-321-44006-4
- Craig McMurtry, Marc Mercuri, Nigel Watling, Matt Winkler: Windows Communication Foundation Unleashed (WCF), Sams Publishing, March 6, 2007, ISBN 0-672-32948-4
- Juval Löwy: Programming WCF Service, O’Reilly Media, Inc., February 20, 2007, ISBN 0-596-52699-7
- Pablo Cibraro, Kurt Claeys, Fabio Cozzolino, Johann Grabner: Professional WCF 4: Windows Communication Foundation with .NET 4, Wrox, June 15, 2010, ISBN 0-470-56314-1
- Andrew Zhu: Microsoft Windows Workflow Foundation 4.0 Cookbook:Chapter 3, Packt Publishing, September 2010, ISBN 978-1-84968-078-3
Hướng dẫn sử dụng WCF Service với C# – 5 bước tạo WCF Service
Bước 1: Tạo project
Mở Visual Studio và tạo một project với tên WcfServiceDemo
Chúng ta có thể xóa 2 file IService1.cs và Service1.svc vì không cần sử dụng chúng
Bước 2: Tạo service
Chuột phải lên project -> chọn Add -> chọn New Item…
Chọn WCF Service -> nhập CalService -> chọn Add
Mở ICalService.cs, xóa hàm “void DoWork()” vàthay vào đó chúng ta sẽ bổ sung chức năng tính tổng 2 số thực (hàm AddNumbers) như sau
Bước 3: Cài đặt Service
Mở CalService.svc, xóa hàm “public void DoWork()” và cài đặt xử lý cho hàm AddNumbers(). Hàm AddNumbers này đã được khai báo tại ICalService.cs
Bước 4: Build
Trong Solution Explorer, chuột phải lên Solution ‘WcfServiceDemo’ -> chọn Build Solution
Hướng dẫn sử dụng WCF Service với C# – Triển khai WCF Service trên IIS
Bước 1: Cài đặt IIS (Nếu máy tính của bạn đã cài IIS thì bỏ qua bước này)
Mở Control Panel -> chọn Programs and Features (trong hình chúng tôi đang sử dụng Windows 10)
Chọn Turn Windows features on or off
Chọn Internet Information Services như hình bên dưới
Ngoài ra, chúng ta cũng phải cài .NET Framework như hình sau
Kiểm tra IIS bằng cách mở trình duyệt và nhập vào http://localhost. Nếu các bạn thấy như hình bên dưới nghĩa là việc cài đặt IIS đã thành công.
Bước 2: Tạo Application
Để khởi động IIS bằng dòng lệnh, chúng ta ở hộp thoại Run và nhập inetmgr -> chọn OK
Chuột phải lên Default Web Site -> chọn Add Application…
Ở hộp thoại Add Application, chúng ta chỉ định thư mục chứa WCF Service project (WcfServiceDemo) mà chúng ta đã thực hiện ở phần trên (5 bước tạo WCF Service)
Nhập WcfServiceDemo tại Alias và chọn OK
Chuột phải lên CalService.svc -> chọn Browse
Chúng ta sẽ nhìn thấy như hình sau (Lưu ý trên thanh địa chỉ của trên duyệt, nơi mà chúng tôi tô màu vàng. Đây sẽ là URL mà chúng ta sẽ dùng để gọi Service tại phía Client)
Keywords searched by users: wcf windows communication foundation
Categories: Chia sẻ 60 Wcf Windows Communication Foundation
See more here: kientrucannam.vn
See more: https://kientrucannam.vn/vn/