WCF Samples


Windows Communication Foundation (WCF) the new API set and runtime for message based communication.

  • WCF replaces old web services as WCF Services support HTTP/Soap 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.

  • WCF replaces old .Net-Remoting communication as WCF Services support binary communication above TCP/IP and named pipes.

    Other channels such as MSMQ and peer messaging channel are supported.

    Also, a flexible extensibility model allows adding new custom protocols and channels.

  • WCF replaces enterprise services as WCF Services support transactions by means of OleTx and WS-Transactions etc.

 

This article contains the following samples:

  • SelfHosting sample: WPF calculator client calling a calculator service by SelfHosting.
  • MessageInterceptor Sample: IClientMessageInspector, IParameterInspector and IDispatchMessageInspector to perform message and parameter interception.

 

SelfHosting sample

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

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()).

 

WCF Samples.zip

Skip to main content