Introduction of the WCF

No.of Views2322
Bookmarked0 times
Downloads 
Votes0
By  ashish shukla   On  06 Sep 2010 09:09:49
Tag : WCF , General
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.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

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.
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. 

Image Loading

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 four types of contracts

Service Contract     Describes the operations of the service
Data Contract          Define the data types passed to and from the service
Fault Contract          Define the erros raised by the service
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 data types 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; }
        }

    }

 Hope this is help to you all.

 

 
Sign Up to vote for this article
 
About Author
 
ashish shukla
Occupation-Not Provided
Company-Not Provided
Member Type-Fresh
Location-India
Joined date-05 Sep 2010
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
By:sdfdsfsdfsfsDate Of Posted:7/5/2011 4:34:35 AM
asf
fdsfsfs
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top
</