Monday, January 31, 2011

What is the Windows Communication Foundation (WCF)?

WCF is a communication library implemented as of version 3.0. NET Framework allows to isolate the "service implementation" of "communication protocol". Besides facilitating the serialization and deserialization of data, this library also offers interchangeable implementations of the main communication protocols. for example:

  • TCP
  • SOAP
  • Named Pipes
  • Message Queues

WCF requires data to be communicated and communication methods are defined at compile time, but the communication protocols, addresses, authentication methods, methods of serialization, encryption method and other details of the communication can be defined in time execution. The configuration of these items can be done without writing code, because for most of the more popular enough to just change an entry in the configuration file.

Some protocols have been implemented in WCF for interoperability with other languages and development platforms, and can be consumed by clients implemented in.. NET WCF also allows you to expose metadata about the service, facilitating the consumption of these.

Services using WCF in IIS or can run normal applications, whether the command line, graphical applications or Windows services. WCF can be used in various settings, allowing quick and efficient implementation of:

  • communication between processes on the same machine (eg. named pipes)
  • webservices
  • web APIs
  • comunicação desconectada (ex: message queue, envie e esqueça)
  • bi-directional communication (eg signature and publication)

The WCF was also implemented in the Mono framework, but only partially.

Translated automatically from my original post in Portuguese.

Tuesday, January 11, 2011

How to make Log4Net to work with a Windows Service assembly?

There are 2 main concerns with using Log4Net with Windows Service:

1. XmlConfigurator must have its Watch property set to true
2. The output log file must be written to a folder where the service user has writing rights

To solve this you can add this line to your AssemblyInfo.cs:

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

And you have to choose a suitable output path such as:

<file value="${ALLUSERSPROFILE}\Company\Product.log" />

Monday, January 10, 2011

Why use "using" instead of calling the "Dispose" method directly?

The following statement:

using(disposable) { }

Has 2 main advantages over the alternative:


  • It handles null variables gracefully
  • It can be easily extended so you can use

using(disposable2) { }

instead of