Blue Theme Orange Theme Green Theme Red Theme
 
Nevron Chart
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » WCF » WCF Overview

WCF Overview

WCF is a .NET platform for developing services .Service is any functionality that can be consumed by the outside world. A service defines well defined communication protocols to communicate with it.

Author Rank :
Page Views : 9922
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Discover the top 5 tips for understanding .NET Interop
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


WCF is a .NET platform for developing services .Service is any functionality that can be consumed by the outside world. A service defines well defined communication protocols to communicate with it.

A service can be located anywhere , it could be on local machine on the intranet or even internet.A client consumes the functionality exposed by the service.A service can be anything it can be an independent application like asp.net or it can be another service.

Client and Service communicate with each other by sending messages.

SOAP Message SOAP Message

Client HTTP/TCP /MSMQ HTTP/TCP/MSMQ Server

WCF.gif

Figure: Basic Client Server Communication

Since the functionality of the service is hidden to the outside world. Service exposes metadata that client uses to communicate with the service. Metadata can be in any technology neutral format like wsdl.

Client always uses proxy to communicate with the service irrespective of where service is located. In WCF every service has endpoints and the client uses theses endpoints to communicate with the service.

Every endpoint has three important pieces of information.

Address , Binding and Contract.

Address specifies the location of the service.

Binding specifies how to communicate with the service(protocol).

Contract specifies what the service does.

A typical endpoint in the configuration file appears as :

<endpoint address = "http://localhost/TestService/" binding="wsHttpBinding"
contract = "MyNamespace.IContract"/>

WCF has mainly following types of contracts

  1. Service Contract: Describes the operations of the services
  2. Operation Contract: Describes the operations available on the service
  3. Data Contract: Define the data types passed to and from the service
  4. Fault Contract: Define the erros raised by the service
  5. Message Contract: Allows the service to interact directly by using the message.

Basic WCF service

System.ServiceModel.dll is the main assembly for WCF services. To create a WCF service we need to apply the service contract attribute either on the interface or the class.

namespace WcfService1
{

     [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        string HelloWorld();

    }

    public class Service1 : IService1
    {      
          public string HelloWorld()
            {
                return "Hello WCF";
            }

      }
}


We can also use explicit interface implementation like this :

         string IService1.HelloWorld()
            {
                return "Hello WCF";
            }


Note when using explicit interface implementation we can't use the public access modifier.

Method Overloading

To use method overloading we need to use the name attribute of the OperationContract attribute.

If we write the following implementation for method overloading it will throw an exception at service host load time.

        [OperationContract]
        string HelloWorld();
 
        [OperationContract]
        string HelloWorld(string Message);


To use method overloading in WCF service we need to use the Name attribute of the OperationContract attribute.

        [OperationContract(Name="HelloWorld")]
        string HelloWorld();
 
        [OperationContract(Name = "HellowWorldMssg")]
        string HelloWorld(string Message);


In the later articles we will see how to host the service and call it using the client application.

Data Contracts

We can pass only the primitive datatypes to OperationContracts .If we want to pass custom data types to OperationContracts we need to use the DataContract Attribute on the Custom datatype.

    [DataContract]
    class Customer
    {
        int name;

        [DataMember]
        public int Name
        {
            get { return name; }
            set { name = value; }
        }
        int address;

        [DataMember]
        public int Address
        {
            get { return address; }
            set { address = value; }
        }

    }

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Ashish Shukla
Having more than 7 years of experience in .NET,C#,Silverlight and SQL Server.Like to read books and travel in spare time.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
DevExpress Free UI Controls
Become a Sponsor
 Comments
Number of contract by devendra On September 9, 2010

There are more then more type of contract in WCF.

Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.