© chinese university, cse dept. distributed systems / 9 - 1 simple example open microsoft visual...

10
Chinese University, CSE Dept. Distributed Systems / 9 - 1 Simple Example • Open Microsoft Visual Studio 2005:

Upload: clarissa-bryant

Post on 20-Jan-2016

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: © Chinese University, CSE Dept. Distributed Systems / 9 - 1 Simple Example Open Microsoft Visual Studio 2005:

© Chinese University, CSE Dept. Distributed Systems / 9 - 1

Simple Example

• Open Microsoft Visual Studio 2005:

Page 2: © Chinese University, CSE Dept. Distributed Systems / 9 - 1 Simple Example Open Microsoft Visual Studio 2005:

© Chinese University, CSE Dept. Distributed Systems / 9 - 2

Simple Example

• Click “File NewWebsite”

• Select the “ASP .NET Web Service” and select C# as the language.

• Click “OK”.

Page 3: © Chinese University, CSE Dept. Distributed Systems / 9 - 1 Simple Example Open Microsoft Visual Studio 2005:

© Chinese University, CSE Dept. Distributed Systems / 9 - 3

Simple Example

• In the windows of Visual Studio, press “Ctrl + F5” to run the default Web service:

Page 4: © Chinese University, CSE Dept. Distributed Systems / 9 - 1 Simple Example Open Microsoft Visual Studio 2005:

© Chinese University, CSE Dept. Distributed Systems / 9 - 4

Simple Example

• Click “HelloWorld” to invoke this function. Click “Invoke” in the shown page, you will get the invocation result:

• By these simple steps, you create a Web service, which contains a simple function named “HelloWorld”

• The address of your Web service is: http://localhost:1336/WebSite1/Service.asmx

•  The WSDL (Web Service Description Language) file of your Web service is available in: http://localhost:1336/WebSite1/Service.asmx?wsdl

• Please note that the port number (1336 in the above example) and Website name (WebSite1 in the above example) may be different in your computer.

Page 5: © Chinese University, CSE Dept. Distributed Systems / 9 - 1 Simple Example Open Microsoft Visual Studio 2005:

© Chinese University, CSE Dept. Distributed Systems / 9 - 5

Simple Example

• The WSDL document of the Web service provides descriptions of the Web service functionalities (e.g., function name, input, output, ect.). By parsing this WSDL file, other programs can invoke this Web service easily.

Page 6: © Chinese University, CSE Dept. Distributed Systems / 9 - 1 Simple Example Open Microsoft Visual Studio 2005:

© Chinese University, CSE Dept. Distributed Systems / 9 - 6

Simple Example

• Use [WebMethod] to add new function Add(int x, int y)• Place Public before the function procedure

Page 7: © Chinese University, CSE Dept. Distributed Systems / 9 - 1 Simple Example Open Microsoft Visual Studio 2005:

© Chinese University, CSE Dept. Distributed Systems / 9 - 7

Simple Example

• Press “Ctrl + F5” to run the Web service which includes two functions, i.e., HelloWorld and Add.

• Click “Add” to invoke the Add function. Type some values into the form and click “Invoke”.

Page 8: © Chinese University, CSE Dept. Distributed Systems / 9 - 1 Simple Example Open Microsoft Visual Studio 2005:

© Chinese University, CSE Dept. Distributed Systems / 9 - 8

Simple Example

• There are a lot of publicly available Web services in the Internet, which provide useful functionalities. We can make use of these Web services by writing codes to invoke them.

• Right click “Website1” and select “Add Web Reference…”

• Type in the Web service address: http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl

• Click “Go” and click “Add Reference” to add the Web service into the project.

Page 9: © Chinese University, CSE Dept. Distributed Systems / 9 - 1 Simple Example Open Microsoft Visual Studio 2005:

© Chinese University, CSE Dept. Distributed Systems / 9 - 9

Simple Example

• Add the following codes to the file “Service.cs”.

• The above codes invoke an Internet Web service named IpAddressSearchWebService to get the geographic information from an IP address. 

• Press “Ctrl + F5” to run the Web service, which includes three functions:

Page 10: © Chinese University, CSE Dept. Distributed Systems / 9 - 1 Simple Example Open Microsoft Visual Studio 2005:

© Chinese University, CSE Dept. Distributed Systems / 9 - 10

Simple Example

• Click “IPAddress”. Type in an IP address and click “Invoke” to get the results:

• Now, your Web service can provides the geographic location service to the user.

• By these simple codes, you have created a Web service, which provides three functions (Helloworld, Add, and IPAddress) to the users. When the third function (i.e., IPAddress) receives a user request, it invokes another Internet Web service to get the results and return the results to the user.