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.
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
Features of WCF
WCF includes the following set of features. For more information, see WCF Feature Details.
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.
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.
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.
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.
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.
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.
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
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.
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.
Windows Communication Foundation (WCF) ni mfumo wa ujenzi wa huduma-oriented maombi. Kwa kutumia WCF, unaweza kutuma data kama ujumbe asynchronous kutoka huduma moja mwisho kwa mwingine. Endpoints huduma inaweza kuwa sehemu ya huduma daima inapatikana mwenyeji na IIS, au inaweza kuwa huduma mwenyeji katika maombi. Mwisho inaweza kuwa mteja wa huduma ambayo inahitaji data kutoka mwisho wa huduma. Ujumbe unaweza kuwa rahisi kama herufi moja au neno kutumwa kama XML, au kama tata kama mkondo wa data binary. Baadhi ya mifano ya matukio ni pamoja na: Huduma salama ya kusindika shughuli za biashara. Huduma ambayo hutoa data ya sasa kwa wengine, kama vile ripoti ya trafiki au huduma nyingine ya ufuatiliaji. Huduma ya mazungumzo ambayo inaruhusu watu wawili kuwasiliana au kubadilishana data kwa wakati halisi. Dashboard programu ambayo polls moja au zaidi ya huduma kwa ajili ya data na inatoa katika uwasilishaji mantiki. "Kufanya kazi kwa kutumia Windows Workflow Foundation kama huduma ya ""WTF""" Wakati kuunda maombi kama hayo ilikuwa inawezekana kabla ya kuwepo kwa WCF, WCF hufanya maendeleo ya mwisho rahisi kuliko hapo awali. Kwa muhtasari, WCF ni iliyoundwa kutoa mbinu manageable kwa ajili ya kujenga huduma za mtandao na wateja wa huduma za mtandao. GRPK ni mfumo wa kisasa wa RPC ambao ni mbadala maarufu wa WCF. GRPC ni msingi wa HTTP2 na ina faida kadhaa juu ya WRCF, ikiwa ni pamoja na: Utendaji: GRPC ni ufanisi zaidi kuliko WRCF, hasa kwa uhusiano wa muda mrefu. - Scalability: gRPC ni iliyoundwa kwa kiwango kwa idadi kubwa ya wateja na seva. Usalama: GRP inasaidia aina mbalimbali ya taratibu za usalama, ikiwa ni pamoja na TLS na uthibitisho. - Msalaba-platform: gRPC ni jukwaa-neutral na inaweza kutumika na aina mbalimbali ya lugha ya programu. Kwa maelezo zaidi juu ya kuendeleza au kuhamia programu za WCF kwa gRPC, angalia: Kwa nini tunapendekeza gRPC kwa watengenezaji wa WCF - Kulinganisha WCF na gRPC - Utangulizi wa gRPC kwa watengenezaji wa WCF. Kwa maelezo zaidi, angalia WCF Feature Details. Wazo la msingi la WFS ni kwamba WFS inakuwezesha kuunda programu za huduma. Ujenzi wa huduma (SOA) ni utegemezi wa huduma za wavuti kutuma na kupokea data. Huduma zina faida ya jumla ya kuwa loosely-kuunganishwa badala ya hard-coded kutoka maombi moja kwa nyingine. Uhusiano loosely-kuunganishwa ina maana kwamba mteja yoyote iliyoundwa juu ya jukwaa yoyote inaweza kuunganisha kwa huduma yoyote kwa muda mrefu kama mikataba muhimu ni kukutana. WFW inatoa huduma za kisasa za mtandao kwa ajili ya huduma za mtandao. Kwa habari zaidi kuhusu viwango vinavyoungwa mkono, angalia Interoperability na Integration. Mfano wa Ujumbe Mengi Ujumbe ni kubadilishana katika moja ya mifumo kadhaa. Mfano wa kawaida ni muundo wa ombi-jibu, ambapo mwisho mmoja huomba data kutoka mwisho wa pili. Mwisho wa pili unajibu. Kuna mifumo mingine kama vile ujumbe wa njia moja ambapo mwisho mmoja hutuma ujumbe bila matarajio yoyote ya jibu. Mfano tata zaidi ni duplex kubadilishana muundo ambapo pointi mbili mwisho kuanzisha uhusiano na kutuma data nyuma na mbele, sawa na programu ya ujumbe wa papo hapo. Kwa habari zaidi kuhusu jinsi ya kutekeleza mifumo tofauti ya kubadilishana ujumbe kwa kutumia WCF angalia Mikataba. WSDL ni metadata ya huduma ya kuchapisha ambayo hutumia muundo ulioainishwa katika viwango vya tasnia kama vile WSDL, XML Schema na WS-Policy. Metadata hii inaweza kutumika kwa moja kwa moja kuzalisha na configure wateja kwa ajili ya kupata huduma WCF. Metadata inaweza kuchapishwa juu ya HTTP na HTTPS au kutumia Web Service Metadata Exchange kiwango. Kwa habari zaidi, angalia Metadata. Kwa sababu WTF ni kujengwa kwa kutumia.NET Framework, pia ni pamoja na code- kirafiki mbinu ya kutoa mikataba unataka kutekeleza. Moja ya aina ya kimataifa ya mikataba ni mkataba wa data. Kwa kweli, wakati wewe code huduma yako kwa kutumia Visual C# au Visual Basic, njia rahisi ya kushughulikia data ni kwa kuunda madarasa kwamba kuwakilisha data chombo na mali kwamba ni mali ya data chombo. WFW ni mfumo wa kazi ya data ya data ambayo inasaidia kufanya kazi na data kwa urahisi. Baada ya kuunda madarasa ambayo inawakilisha data, huduma yako moja kwa moja inazalisha metadata ambayo inaruhusu wateja kufuata aina za data ambazo umebuni. Kwa habari zaidi, angalia Kutumia Mikataba ya Takwimu. Ujumbe unaweza kuwa encrypted kulinda faragha na unaweza kuhitaji watumiaji kuthibitisha wenyewe kabla ya kuruhusiwa kupokea ujumbe. Usalama unaweza kutekelezwa kwa kutumia viwango vinavyojulikana kama vile SSL au WS-SecureConversation. Kwa habari zaidi, angalia Usalama. Usafiri mbalimbali na Encodings Ujumbe inaweza kutumwa juu ya yoyote ya kadhaa kujengwa katika itifaki ya usafiri na encodings. Ujumbe wa SOAP ni mfumo wa mawasiliano wa kawaida wa mawasiliano ya mtandao unaotumia HyperText Transfer Protocol (HTTP) ambayo hutumiwa kwenye mtandao wa mtandao. Kwa upande mwingine, WCF inaruhusu wewe kutuma ujumbe juu ya TCP, majina mabomba, au MSMQ. Ujumbe huu unaweza kuwa encoded kama maandishi au kutumia optimized binary format. Takwimu binary inaweza kutumwa kwa ufanisi kwa kutumia kiwango cha MTOM. Kama hakuna ya usafirishaji zinazotolewa au encodings kukidhi mahitaji yako unaweza kuunda usafirishaji yako mwenyewe desturi au encoding. Kwa habari zaidi kuhusu usafirishaji na encodings mkono na WCF angalia Usafirishaji. Ujumbe wa kuaminika na Queued: WMSF inasaidia kubadilishana ujumbe wa kuaminika kwa kutumia vikao vya kuaminika vilivyotekelezwa juu ya Ujumbe wa Kuaminika wa WS na kutumia MSMQ. Kwa habari zaidi kuhusu msaada wa ujumbe wa kuaminika na wa mstari katika WCF, angalia Mstari na Vikao vya Kuaminika. Ujumbe wa kudumu ni ule ambao hauwezi kupotea kamwe kwa sababu ya kuvunjika kwa mawasiliano. Ujumbe katika muundo wa ujumbe wa kudumu ni daima kuhifadhiwa kwa database. Kama usumbufu hutokea, database inaruhusu wewe kuendelea na kubadilishana ujumbe wakati uhusiano ni kurejeshwa. Unaweza pia kuunda ujumbe wa kudumu kwa kutumia Windows Workflow Foundation (WF). Kwa habari zaidi, angalia Huduma za Mtiririko wa Kazi. WTF pia inasaidia shughuli kwa kutumia moja ya tatu shughuli mifano: WTF, APIs katika System.Transactions namespace, na Microsoft Distributed Transaction Coordinator. Kwa habari zaidi kuhusu msaada wa shughuli katika WCF angalia shughuli. AJAX na REST Support WCF usanifu ina idadi ya pointi extensibility. Kama uwezo wa ziada inahitajika, kuna idadi ya pointi ya kuingia ambayo kuruhusu wewe kubadili tabia ya huduma. Kwa habari zaidi kuhusu pointi extensibility inapatikana angalia Extending WCF. WTF ni pamoja na teknolojia nyingine za Microsoft, na ni rahisi sana kutumia. Kwa sababu ya kubadilika kwa hali ya juu, WCF pia hutumiwa katika bidhaa zingine kadhaa za Microsoft. Kwa kuelewa msingi wa WF, una faida ya mara moja ikiwa pia unatumia yoyote ya bidhaa hizi. Teknolojia ya kwanza ya kuunganisha na WCF ilikuwa Windows Workflow Foundation (WF). Workflows kurahisisha maombi ya maendeleo kwa encapsulating hatua katika workflow kama "shughuli". Katika toleo la kwanza la Windows Workflow Foundation, developer alikuwa na kuunda mwenyeji kwa ajili ya mtiririko wa kazi. Toleo la pili la Windows Workflow Foundation ilijumuishwa na WCF. Hii inamaanisha kwamba kazi yoyote inaweza kuhifadhiwa kwa urahisi katika huduma ya WCF. Unaweza kufanya hivyo kwa kuchagua aina ya mradi wa WFWF katika Visual Studio 2012 au baadaye. Microsoft BizTalk Server R2 pia hutumia WCF kama teknolojia ya mawasiliano. BizTalk ni iliyoundwa kupokea na kubadilisha data kutoka moja ya muundo wa kawaida kwa mwingine. Ujumbe lazima utolewe kwenye sanduku lake kuu la ujumbe ambapo ujumbe unaweza kubadilishwa kwa kutumia ramani kali au kwa kutumia moja ya vipengele vya BizTalk kama injini yake ya mtiririko wa kazi. Kwa mfano, unaweza kutumia adapter ya WF-LOB (Line of Business) ili kuhamisha ujumbe kwenye sanduku la ujumbe. Vipengele vya hosting vya Windows Server AppFabric Application Server vimeundwa hasa kwa ajili ya kupeleka na kusimamia maombi ambayo hutumia WCF kwa ajili ya mawasiliano. Vipengele vya kukaribisha ni pamoja na zana tajiri na chaguzi za usanidi maalum iliyoundwa kwa ajili ya maombi WCF-kuwezesha.