Posts

Showing posts from January, 2011

Web Services and WCF services

Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service, following table provides detailed difference between them. Features Web Service WCF Hosting It can be hosted in IIS It can be hosted in IIS, windows activation service, Self-hosting, Windows service Programming [WebService] attribute has to be added to the class [ServiceContraact] attribute has to be added to the class Model [WebMethod] attribute represents the method exposed to client [OperationContract] attribute represents the method exposed to client Operation One-way, Request- Response are the different operations supported in web service One-Way, Request-Response, Duplex are different type of operations supported in WCF XML System.Xml.serialization name space is used for se

Exploring our Lazy Class

We’ll dive in by writing an generic class that represents the delayed (and lazy) computation, Lazy<T>.  Actually it is just a class that will execute a piece of code once somebody asks for the a result. It will also need to cache this result, so that we can enforce that the code is at most executed once. It is pretty easy to represent this in C#: for the ‘piece of code’ that we need to execute, we can use a Func   delegate. We’ll also use generics, since this ‘piece of code’ can return any .NET type. public class Lazy<T> {     private Func<T> func;     private T result;     private bool hasValue;     public Lazy(Func<T> func)     {         this .func = func;         this .hasValue = false ;     }     public T Value     {         get         {             if (! this .hasValue)             {                 this .result = this .func();                 this .hasValue = true ;             }             return this .result;         }     } } Our new cl