Windows Communication Foundation

The Windows Communication Foundation (WCF, formerly code-named Indigo ) is a service-oriented communication platform for distributed applications in Microsoft Windows. It brings together many network functions and makes them standardized available to programmers of such applications.

Through the WCF communication technologies DCOM, Enterprise Services, MSMQ, and WSE web services are combined under a unified programming interface. The main field of application of WCF is the development of service-oriented architectures. The Windows Communication Foundation also enables interoperability with Java Web Services which have been implemented using Web Services Interoperability Technology.

The Windows Communication Foundation is for. NET Framework version 3.0, an integral part of. NET framework. The version numbers of WCF based this on the version of. NET framework.

  • 2.1 Implementation of Contracts
  • 2.2 Implementation of the Services
  • 2.3 Imperative implement a host application
  • 2.4 Implementation of a client
  • 2.5 Declarative implementation of a host application
  • 2.6 WCF Service Host and WCF Test Client

Concept

The WCF abstracts the concept of the end point by separating Address, Binding and Contract (ABC - principle).

  • The Address ( address) is a URI that describes the location of the service and thereby identifying its accessibility for service consumers.
  • The Contract (Contract) provides the service definition, including the methods made ​​available including, dar.

Binding

Binding to include parameters such as protocol (HTTP, TCP, UDP, and Windows - specific protocols ) and encoding (binary, SOAP document, own format ), and safety aspects (encryption, authentication).

NET Framework The. Provides prebuilt bindings for common applications available that can still be configured. There is also the opportunity to develop their own bindings ( for example, for the XML -RPC protocol).

Contract

Contracts are written at development time as interfaces (interfaces) in any. NET language and runtime by the WCF implemented in a communication protocol such as SOAP. The use of this standard is essential for a platform-independent service access.

Behaviors

The behavior of a WCF connection is defined by behaviors. A distinction is made depending on the range between:

  • Service Behavior
  • Endpoint Behavior
  • Contract Behavior
  • Operation Behavior

Examples

The following are examples for the implementation of a simple WCF service are shown.

Implementation of Contracts

The Contract is used by both the host as well as from the client application and should be in its own assembly therefore.

Using HelloWorld.Contract;   namespace HelloWorld.Service {      public class HelloWorld service: IHelloWorldService      {          public string SayHello ()          {              return " Hello World";          }      } } Imperative implement a host application

Using System; using System.ServiceModel; using HelloWorld.Contract; using HelloWorld.Service;   namespace HelloWorld.ConsoleHost {      class Program      {          static void Main ()          {              using ( var host = new ServiceHost (typeof ( Hello World Service ), new Uri ( " http://localhost:8000/HelloWorld ")))              {                  host.AddServiceEndpoint (typeof ( IHelloWorldService ), new BasicHttpBinding (), " Hello Indigo Service");                  host.Open ();                  Console.WriteLine (" Press ENTER to stop running service. . ");                  Console.ReadLine ();              }          }      } } Implementation of a client

Using System; using System.ServiceModel; using HelloWorld.Contract;   namespace HelloWorld.ConsoleClient {      class Program      {          static void Main ()          {              var EndpointAddress = new EndpointAddress ( " http://localhost:8000/HelloWorld ");              var proxy = ChannelFactory CreateChannel (new BasicHttpBinding (), EndpointAddress ). ;              var helloWorld = proxy.SayHello ();              Console.WriteLine ( hello world );          }      } } Declarative Implementation of a host application

Using System; using System.ServiceModel; using HelloWorld.Contract; using HelloWorld.Service;   namespace HelloWorld.ConsoleHost {      class Program      {          static void Main ()          {              using ( var host = new ServiceHost (typeof ( Hello World Service )))              {                  host.Open ();                  Console.WriteLine (" Press ENTER to stop running service. . ");                  Console.ReadLine ();              }          }      } } The behavior of the service is declared in the file App.config or Web.config. This is usually done with the Service Configuration Editor ( SvcConfigEditor.exe ) and can also be configured by experienced developers and administrators in a text editor manually.

                                                                                                             < / bindings >                                                                                                                                           < endpoint                      address = " "                      binding = " basicHttpBinding "                      bindingConfiguration = " basicHttpBinding configuration"                      name = " basicHttpEndpoint "                      contract = " HelloWorld.Contract.IHelloWorldService " />                  < endpoint                      address = " mex "                      binding = " mexHttpBinding "                      bindingConfiguration = " mexHttpBindingConfiguration "                      name = " mexEndpoint "                      contract = " IMetadataExchange " />                                                                                                                   < / service>               By activating the metadata exchange (English: Metadatata Exchange, or " mex " ) through the use of an appropriate bindings (for B.mexHttpBinding, mexHttpsBinding, mexTcpBinding, mexNamedPipeBinding ), the proxy class and application configuration can use the ServiceModel Metadata Utility ( svcutil.exe ) are automatically created.

The generated proxy class and application configuration can be easily consumed by a client.

Another option is to host the service directly using the WCF Service Host ( WcfSvcHost.exe ).

Ongoing services that support metadata exchange can be analyzed and tested using the WCF Test Client ( WcfTestClient.exe ).

825932
de