Friday, May 15, 2009

How to write WCF Services in Microsoft Visual Studio 2008

How to write WCF Services in Microsoft Visual Studio 2008

open visual studio 2008
1. Create New project
2. go to WCF tab
3. select WCF Service Library
4. Name the folder name called library: e.g. Calculator and then click ok.
5. Rename the Services name of project as you wish
6. general convention is just adding the word Service after library name e.g.: CalculatorService on .cs file and interface file ICalculatorService.cs
7. make some function like as: add
on CalculatorService.cs file

namespace CalcAreaWcf
{
public class CalcAreaWcfService : ICalcAreaWcfService
{
public double CalcAreaSquare(float fY)
{
double calcValue = fY * fY;
return calcValue;
}

}
}

on ICalcAreaWcfService.cs file

namespace CalcAreaWcf
{

[ServiceContract]
public interface ICalcAreaWcfService
{
[OperationContract]
double CalcAreaSquare(float fY);
}
}


8. add reference: System.ServiceModel
9. change the name of service on app.config as well. eg CalcAreaWcfService and ICalcAreaWcfService
10. build the service

i thing it should build, if u want to run the service then press Ctrl+F5 you can see the running service on localhost.


Cheers! then you are able to build WCF Service

No comments:

Post a Comment