Monday, February 7, 2011

sample program in wcf for Beginners

Hi, In this article i would like to explain a WCF sample program.we already know WCF Means Windows communication Foundation.where WCF services is not but advanced Web services.Now i am going to explain wcf  sample application..just the follow the steps..after that we will discuss breifly.


First, open the Microsoft visual studio 2008 and select a WCF Service

Application and change the name as NewWcf and click OK Button

Next,open the service.svc.cs file add the following code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace NewWCF
{
    // NOTE: If you change the class name as "ownservice" here, you must

also update the reference to "ownservice" in Web.config.
    public class ownservice : Iownservice
    {
        public void DoWork()
        {
        }
        public string values(string value)
        {
            return "hello"+value;
        }
        public int Add(int x, int y)
        {
            return x + y;
        }
    }
}

Next,Save and Run the project and copy the url in the address bar of the

browser

Next,open the new web application and Right click on the project in the solution explorer and add service Reference

Next,Paste the url which you copied before in the address bar and press ok

Next,Open the Default.aspx page and drag and drop one button from the toolbox

Next,Double click on the button and add the following button
protected void Button1_Click(object sender, EventArgs e)
        {

            ServiceReference1.IownserviceClient sec = new testwcf.ServiceReference1.IownserviceClient();
            sec.Open();
            Response.Write(sec.values("jodha"));
            Response.Write(sec.Add(3, 3));
            sec.Close();
        }
Finally..Run the program .....That's it
developercode
About the Author
Sayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

Labels: , , , , ,

4 Comments:

At April 20, 2011 at 3:51 PM , Anonymous Anonymous said...

Nice post for Beginners

 
At April 20, 2011 at 3:52 PM , Anonymous Anonymous said...

thanks for sharing taanu ji.....

 
At June 28, 2011 at 10:17 AM , Anonymous Anonymous said...

Nice post for Beginners

 
At June 28, 2011 at 10:17 AM , Anonymous Anonymous said...

thanks for sharing taanu ji.....

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home