addtion and subtraction program

7
8/19/2019 addtion and subtraction program http://slidepdf.com/reader/full/addtion-and-subtraction-program 1/7 CREATE A COMPONENT THAT RECEIVES TWO NUMBERS FROM THE USER THROUGH A WEB FORM, AND BASED ON THE USER’S SELECTION ADD OR SUBTRACT THE TWO NUMBERS AND RETURNS THE RESULT TO THE WEB FORM. THE RESULT SHOULD BE DISPLAYED IN THEWEB FORM USING ASP.NET Step -1 First open your visual studio --> File -->New -->Select ASP.NET Empty Website and select Visual C# from left window -->!-->Now pen Solution E"plorer-->Now #i$%t clic& on website --> Add New 'tems --> Select web service ( Visual C# --> Write your web service)s name *calculationservices.asm"+ --> clic& Add button as s%own below,- Step -2 Now Write t%e lo$ic codes for calculation under / WebMethod 0 as $iven below,- using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; /// <summary> /// Summary description for calculationservices /// </summary>

Transcript of addtion and subtraction program

Page 1: addtion and subtraction program

8/19/2019 addtion and subtraction program

http://slidepdf.com/reader/full/addtion-and-subtraction-program 1/7

CREATE A COMPONENT THAT RECEIVES TWO NUMBERS FROM THE USER THROUGHA WEB FORM, AND BASED ON THE USER’S SELECTION ADD OR SUBTRACT THE TWONUMBERS AND RETURNS THE RESULT TO THE WEB FORM. THE RESULT SHOULD BE

DISPLAYED IN THEWEB FORM USING ASP.NET

Step -1 First open your visual studio --> File -->New -->Select ASP.NET Empty Website andselect Visual C# from left window --> !-->Now pen Solution E"plorer-->Now #i$%t clic& on website --> Add New 'tems --> Select web service ( Visual C# --> Write your web service)sname *calculationservices.asm"+ --> clic& Add button as s%own below,-

Step -2 Now Write t%e lo$ic codes for calculation under / WebMethod 0 as $iven below,-

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Services;

/// <summary>/// Summary description for calculationservices/// </summary>

Page 2: addtion and subtraction program

8/19/2019 addtion and subtraction program

http://slidepdf.com/reader/full/addtion-and-subtraction-program 2/7

WebService!"amespace # $%ttp&//tempuri.org/$'(WebService)inding!Conforms*o # Wsi+rofiles.)asic+rofile,-,'(

// *o allo t%is Web Service to be called from script using 0S+."1* 0203 uncommentt%e follo ing line.// System.Web.Script.Services.ScriptService(public class calculationservices & System.Web.Services.WebService 4

public calculationservices !' 4

//5ncomment t%e follo ing line if using designed components//6nitiali7eComponent!';

8

Web9et%od( public int add!int i int :' 4 return i :; 8

Web9et%od( public int substract!int i int :' 4 return i :; 8 Web9et%od( public int multiply!int i int :' 4 return i = :; 8

Web9et%od( public int ivision!int i int :'

4 return i / :; 8

Web9et%od( public int modulos!int i int :' 4 return i ? :; 8 8

Step -3 Now #un t%is web services *calculationservices.asm"+ -->Now #i$%t lic& Website in

Solution E"plorer --> Select 1uild Website

Ne"t #i$%t lic& Website in Solution E"plorer --> Select 2iew in 1rowser

Now Select the file calculationservices.asmx

Page 3: addtion and subtraction program

8/19/2019 addtion and subtraction program

http://slidepdf.com/reader/full/addtion-and-subtraction-program 3/7

Step -4 Now you can calculate your services*Addition3Subtraction34ultiplication35ivision andmodulus + -->clic& 5ivision lin& or ot%ers as s%ow below,-

Step -5 Now clic& 'nvo&e 1utton -->you will see 3output will s%ow in 647 5ocument formatusin$ S AP Protocol.

Page 4: addtion and subtraction program

8/19/2019 addtion and subtraction program

http://slidepdf.com/reader/full/addtion-and-subtraction-program 4/7

Step -6 Now open your visual studio a$ain--> File -->New -->Select ASP.NET Empty Websiteand select Visual C# from left window --> !-->Now pen Solution E"plorer-->Now #i$%tclic& on website --> Add New Web Form *webservice.asp"+ --> 5ra$ and drop 7abel 3Te"t 1o"and 1utton control on t%e Form as s%own below,-

Note ,-

• web service extension --> .asmx

• Web Form Extension --> .aspx

• Disco File Extension --> .d s!"

Step - Now open your solution E"plorer -->#i$%t lic& on your application *website+ -->Add Web #eference -->Paste web service 8#7 %ere *W%ic% i %ave already copied in step 9+ --> lic&Ne"t Arrow as s%ow below,-

Page 5: addtion and subtraction program

8/19/2019 addtion and subtraction program

http://slidepdf.com/reader/full/addtion-and-subtraction-program 5/7

Note ,- :ou can copy t%e 8#7 by #un t%e web service a$ain.

Step -! Now Write t%e web service)Name * " service + --> lic& Add #eference 1utton.as s%own below ,-

Step -$ :ou will see 3t%ere are some files are added in your application*w%en we complete t%e web service confi$uration+ as s%own below,-

Page 6: addtion and subtraction program

8/19/2019 addtion and subtraction program

http://slidepdf.com/reader/full/addtion-and-subtraction-program 6/7

Note ,- See above image carefully:-

• nclu!e a Name s"ace in webservice.as"x.cs file as #sing myservice$

• %reate ob&ect of calculationservices in webservice.as"x.cs file as calculationservices ob& ' newcalculationservices()$.

Step -1% Now write t%e c codes on button clic& in #$%s$&' !$.aspx.!s file by !ouble clic*ing the button as given below:-

using System;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using myservice;public partial class webservice : System.Web.UI. Page{ protected void Page_ oad! ob"ect sender# $vent%rgs e& {

'

protected void (utton)_Clic*! ob"ect sender# $vent%rgs e& { calculationservices ob" + new calculationservices !&; ,,you can use below wit-out include amespace!using myservice;& ,,myservices.calculationservices ob" + new myservices.calculationservices!&; int sum + ob".add! Convert ./oInt01!/e2t(o2)./e2t&# Convert ./oInt01!/e2t(o21./e2t&&; abel)./e2t + 34our addition 5esult +3 6 sum./oString!&; ,,you can use below script instead o7 abel control ,,5esponse.Write!38script9 alert!3 6 sum 6 3&8,script93&; '

protected void (utton1_Clic*! ob"ect sender# $vent%rgs e&

Page 7: addtion and subtraction program

8/19/2019 addtion and subtraction program

http://slidepdf.com/reader/full/addtion-and-subtraction-program 7/7

{ calculationservices ob" + new calculationservices !&; int sub + ob".substract! Convert ./oInt01!/e2t(o2)./e2t&# Convert ./oInt01!/e2t(o21./e2t&&; abel)./e2t + 34our Substraction 5esult +3 6 sub./oString!&; ,,you can use below script instead o7 abel) control ,,5esponse.Write!38script9 alert!3 6 sub 6 3&8,script93&; '

protected void (utton0_Clic*! ob"ect sender# $vent%rgs e& { calculationservices ob" + new calculationservices !&; int mult + ob".multiply! Convert ./oInt01!/e2t(o2)./e2t&# Convert ./oInt01!/e2t(o21./e2t&&; ,,5esponse.Write!38script9 alert!3 6 mult 6 3&8,script93&; abel)./e2t + 34our ultiplication 5esult +3 6 mult./oString!&; '

protected void (utton _Clic*! ob"ect sender# $vent%rgs e& { calculationservices ob" + new calculationservices !&; int div + ob".<ivision! Convert ./oInt01!/e2t(o2)./e2t&# Convert ./oInt01!/e2t(o21./e2t&&; abel)./e2t + 34our <ivison 5esult +3 6 div./oString!&; ,,you can use below script instead o7 abel) control ,,5esponse.Write!38script9 alert!3 6 div 6 3&8,script93&; '

protected void (utton=_Clic*! ob"ect sender# $vent%rgs e& { calculationservices ob" + new calculationservices !&; int mod + ob".modulos! Convert ./oInt01!/e2t(o2)./e2t&# Convert ./oInt01!/e2t(o21./e2t&&; abel)./e2t + 34our odulos 5esult +3 6 mod./oString!&; ,,you can use below script instead o7 abel control

,,5esponse.Write!38script9 alert!3 6 mod 6 3&8,script93&; ''

Step -11 Now #un t%e Application *webservice.asp"+ --> Now #i$%t lic& Website in SolutionE"plorer --> Select 1uild Website

Ne"t #i$%t lic& Website in Solution E"plorer --> Select 2iew in 1rowser

Now Select the file webservice.asp"

Enter t%e Te"t 1o" Fields -->press eac% button* Add3 Subtract......... + to view t%e output.