Go to VS.NET click on File click on new click on website select WCF service Template select the language as visual c# select the location as http type the service application name (http://Local host /example1) Click on OK.
When we create a web service by default 3 files will be created.
1) I service .cs (this is an interface file that contains service contracts & Data contracts).
2) service .cs (this is a class file & contains an implementation of the interface file)
3) service.svc ( this is WCF service file) First 2 files i.e., I service.cs & service.cs are placed in a separate folder “app_code” Double click on app-code folder change I service.cs file name ot “I arithematic.cs” Change the service.svc filename to “clsarithematic.svc” Double click on I arithmetic.cs file change the interface name to I Arithmetic Delete the code available in interface Delete the code from data contract attribute to remaining
Write the following code in the interface,
[service contract] Public interface I Arithmetic
{
[operationcontract] Int add (int x, int y): [operation contract] Int subtract (int x, int y);
[operationcontract] Int multiply (int x, int y);
[operationcontract] Int divide (int x, int y);
}
Go to solution explorer à Double click on cls Arithmetic file in app-code folder à change the class ham ot cls arithmetic which inherits from I Arithmetic interface à Delete the total code available in the class & write the following code, Public class cls Arithmetic: I arithmetic
Interested in mastering VB.Net Training? Enroll now for a FREE demo on "VB.Net Training"
{
Public int add (int x, inty) } Return x to y: }
Public int subtract (intx, inty) { return x-y; }
Public int multiply (intx, inty) { return x*y; }
Public int divide (int x, int y) { return x/y; }
}
Go to solution explorer double click on web.config fole Go to the tag<system.servicemodel> change the service name to clsarithematic & contract to I arithematic like,
<system.servicemodel>
<services>
<service name =”cls arithematic” ……………….>
<end point address – “” binding = “Wshttpbinding” contract = “ I Arithematic”>
Goto solution explorer double click on cls Arithmetic .svc change the name service to cls arithmetic & code behind file name also from service.cs to cls arithmetic.cs build the application & run the application.
Create a new website with the name “ check Example 1” Design the webpage Go to solution exploreràselect the solution click with a right mouse button click on “Add service reference “ Type http://local host /example1/arithematic.svc” in dropdown list box (this is the address we get in the address bar of internet explorer we run WCF service ) change the namespace name “ service reference 1” to “SR1” click on ok write the following code,
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.