Title: ECT 7120 Distributed Systems and Software
1ECT 7120 Distributed Systems and Software
- Web Services and .NET Demonstration
2Component needed
- IIS (Internet Information Services, latest
version 6.0) - .NET Framework (latest version 1.2)
- Visual Studio .NET 2005
31. Creating Web Services with .NET
- Step1 click New ? Web Site ? ASP .NET Web
Service, choose the language you want. (Visual
C, VB, Visual J...) - Step2 Right click Service1.asmx and select View
Code to enter the code design window - Step3 Use ltWebMethod()gt to add new function
(place Public before the function procedure) - WebMethod
- public int Add(int x, int y)
-
- int result
- result x y
- return result
-
4Create Web Services
5Add Method in Web Services
6Creating Web Services with .NET
- Step4 click start to execute the web services
- A browser will appear with the Add method
displayed and hyperlinked - Click Add to open another browser to perform the
add function - Type in two values (X and Y) then click invoke to
get the result - The result will be returned in XML format
- Students can try to browse the web service in the
server - http//137.189.89.81/demo/Service.asmx
7Execute the Web Services
http//137.189.89.81/demo/Service.asmx
8Execute the Web Services
9View XML Result in Browser
102. Calling Web Services with .NET
- From local host
- Create a new ASP .NET Web Application (say
WebApplication1) - Right click App_WebReferences and select Add
Web Reference - Type in the appropriate path where the Web
Service is located - http//137.189.89.81/demo/Service.asmx
- Create a Web form interface
- In aspx.cs
- protected void Button1_Click(object sender,
EventArgs e) -
- if ((this.tbX.Text ! "")
(this.tbY.Text ! "")) -
- Addition.Service service new
Addition.Service() - this.lbResult.Text
service.Add(int.Parse(this.tbX.Text),
int.Parse(this.tbY.Text)).ToString() -
-
11Calling Web Services -- C
12Calling Web Services -- .aspx
13Calling Web Services -- result
http//137.189.89.81/WebSite2/Default.aspx
143. Application Sample with C
- Create a new Visual C Projects, says Window
Form Application. - Right click the project name and select Add Web
Reference - Type in the appropriate path where the Web
Service is located - http//137.189.89.81/demo/Service.asmx
- Create a Dialog-based interface
- Code
- AddService ws
- int result
- result ws.Add (1, 2)
- SystemWindowsFormsMessageBoxShow
(SystemStringFormat("0", result))
15Application Sample with C
16Application Sample with C
17Application Sample with C
18(No Transcript)
19Application Sample with C