6/03/2011

Step by Step WCF example

Step by step procedure to create WCF:

A.Creating the service (Server side)

Step 1: Open Visual Studio 2010 and create project ,choose  "Windows Service  Application", and give a name to your project say MyService.

Step 2: Open IService.cs  , in that you can see [ServiceContract] where your intetface name is declared and [OperationContract] here you function contract should be defined here (note: delete the default functions if they are not needed), initialize you addData function here




Step 3: Open Service1.svc.cs and add the code for the addData function, ( note: delete the default functions if they are not needed)

                                  

Step 4: Declare your endpoint in web.config file add the below code which is in  bold and Italics.
                                 
                                   

Step 5:Save the project and run it

                                       
B. Creating the client to consume the service (Client side):

Step 1: Open another Visual studio 2010 , create a new ASP.net web application.right click the project and go to 'Add Service reference' ,copy and paste the service  url and press OK

Step 2: Open Default.aspx , create a simple button and lable controls

Step 3: Double click the button and add this following code

                                         

Ste 4: Build and run the project ,now your client has comsumed the services!!

                                          

read more

msdn :http://msdn.microsoft.com/en-us/library/ms734712.aspx 

No comments:

Post a Comment