Fremus.co.za

Demistifying Life and Web Development

WCF – Getting the foundations right

Ok so admittedly I have been using ASMX services for too long now and the time has come to kick it to the curb and adopt WCF. And the issue I have been having of late was that I was skimming through code just to get stuff done, without spending the time understanding some of the details.

Why would I want to adopt WCF? Well there are the list of reasons found in articles on MSDN, one whitepaper can be found here, and of particular interest is the combination of technologies and the general idea that interoperability is the main goal. But these things are just a way of promoting the technology, and its not until you understand what it can do that you realise what it is you are dealing with. And to help you get to that point you need to work through an example, and I found that after I worked through the “Getting Started Tutorial” example, a light went on and I was like, “ok I get it”. Essentially a WCF service is made up of two key elements (there is a third as well) but in terms of C# code there are two key elements:
*An interface marked as a Service Contract using the ServiceContract attribute and with the methods marked as OperationContracts using an attribute with the same name
*A class that implements the methods in the interface

The third part of a WCF service is the configuration settings which can be found in a web.config/app.config’s system.servicemodel tag. Within the servicemodel section you define service behaviours as well as endpoints. One of the keys to understanding WCF is knowing that a service is defined by its endpoint, see it as a consumer. WCF can be consumed by client web apps, Silverlight apps and desktop apps. The endpoints themselves have configuration settings as well specifically relating to message sizes.

From the tutorial I was able to see that you can run a WCF service in a browser, without having IIS running. Thats something I need to think about but it does pose a few interesting questions. After I did the tutorial I wanted to do a simple REST service, and that took a few minutes but eventually got that sorted. StackOverflow was quite helpful and so was several articles on MSDN, with this one being the most helpful.

  • Share/Bookmark
posted by fr3dr1k in C#,WCF and have No Comments
Tags: ,

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment
Get Adobe Flash playerPlugin by wpburn.com wordpress themes