Friday, 2 May 2008

WCF primer - essentials

This is part 1 of the wcf primer. Landing page can be found here.

So, what is wcf?
WCF is basically the new distributed applications paradigm. Instead of having multiple distributes application stacks, web services, remoting, msmq and whatnot, there is but one stack to grok.

The brilliance of wcf can be seen in the endpoints mechanism...
A service Foo can be exposed over both Http, WsHttp and remoting, basically without changing the code !

Essentials

  • Service
    If you take a step back from the implementation view, a service is basically just a class that offers a number of methods that provide some (business) functionality.  Wether or not this service is outside of your application (ie requires you to cross a service boundary) isn't important. Imho, any ILogger or ISomethingProvider can be considered as a service. 
    However, seeing as this is a number of posts about WCF, a service is a class that offers functionality to remote clients.  To be considered a WCF service this class must implement a ServiceContract.
  • ServiceContract
    A service contract is an interface (defined or inferred) which has a number of methods marked with the OperationContract attribute.  The service contract itself must have the ServiceContract attribute applied.
  • Service Operation
    A method marked with the OperationContract attribute.
  • DataContract
    A combined set of primitive values and/or other data contracts to be sent as parameters of return value from a Service operation. 
    A class with the DataContract attribute applied.  Any member that you want to send over the wire should be marked with DataMember attribute.
  • Hosting
    Before a service can be called, it must have a process that runs it and exposes it to the outside world.  More on the hosting stuff in a later post.
  • Address
    An address is basically an url, which is comprised of a scheme, domain, (optional) port and path
    http://something.com:80/service
    net.tcp//localhost:9000
  • Bindings
    A binding is a the sum of a transport protocol, an encoding format and a number of properties.

    for instance: BasicHttpBinding = http protocol, soap encoding, non transactional and so on
  • Endpoints
    A hosting process can expose a service in multiple ways, for instance over Http, over Tcp and so on.  One service can be exposed over multiple endpoints.  An endpoint can be seen as (address + binding =) way to contact a service.
  • Metadata
    While technically not really a new concept, the following point about metadata needs to be made.  In the good old days you just pointed at any webservice and added the ?wsdl tag to get the metadata back.  This is no longer the case.
    WCF takes the opt-in approach.  If you want something to happen, you need to explicitly tell wcf to do it. 

0 comments: