Windows Communication Foundation (WCF) the new API set and runtime for message based communication.
In particular, WCF now supports WS* standards for secure, reliable communication etc.
Also, WCF services can be hosted by IIS Services, WAS or they can be self hosted into a custom application.
Other channels such as MSMQ and peer messaging channel are supported.
Also, a flexible extensibility model allows adding new custom protocols and channels.
This article contains the following samples:
Selfhosting sample shows a WPF windows application that implements a client for the calculator service.
The calculator client performs the calculations calling the CalculatorService component.
The following diagram shows the CalculatorClient and CalculatorService components.
The CalculatorService is SelfHosted into the client application by means of the following code:
The service configuration below shows that at startup 2 endpoint listeners are loaded do that the service can be connected by means of TCP/IP or by named pipes:
With the following configuration the calculator clients connects the selfhosted service by means of the tcp/ip endpoint:
MessageInterceptor sample shows using the WCF extensibility model to intercept client application calls at class and method level.
This can be done creating a WCF Behaviour class for the service and attaching it to the service by means of the configuration.
Client Interception is performed by means of IClientMessageInspector, IParameterInspector interfaces and Service interception is performed IDispatchMessageInspector, IParameterInspector.
The MessageInterceptorClass shown below implements all the interfaces to provide CalculatorService interception at the client and dispatcher side.
The message interceptor is installed into the client or dispatcher side by means if a Behaviour.
MessageInterceptorBehaviour class below shows how to install the interceptor class at the client side (ApplyClientBehaviour()) or dispatcher side (ApplyDispatchBehaviour()).