Simple Example Open Microsoft Visual Studio 2005 Chinese

  • Slides: 10
Download presentation
Simple Example • Open Microsoft Visual Studio 2005: © Chinese University, CSE Dept. Distributed

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

Simple Example • Click “File New Website” • Select the “ASP. NET Web Service”

Simple Example • Click “File New Website” • Select the “ASP. NET Web Service” and select C# as the language. • Click “OK”. © Chinese University, CSE Dept. Distributed Systems / 9 - 2

Simple Example • In the windows of Visual Studio, press “Ctrl + F 5”

Simple Example • In the windows of Visual Studio, press “Ctrl + F 5” to run the default Web service: © Chinese University, CSE Dept. Distributed Systems / 9 - 3

Simple Example • Click “Hello. World” to invoke this function. Click “Invoke” in the

Simple Example • Click “Hello. World” 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 “Hello. World” The address of your Web service is: http: //localhost: 1336/Web. Site 1/Service. asmx The WSDL (Web Service Description Language) file of your Web service is available in: http: //localhost: 1336/Web. Site 1/Service. asmx? wsdl Please note that the port number (1336 in the above example) and Website name (Web. Site 1 in the above example) may be different in your computer. © Chinese University, CSE Dept. Distributed Systems / 9 - 4

Simple Example • The WSDL document of the Web service provides descriptions of the

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. © Chinese University, CSE Dept. Distributed Systems / 9 - 5

Simple Example • Use [Web. Method] to add new function Add(int x, int y)

Simple Example • Use [Web. Method] to add new function Add(int x, int y) • Place Public before the function procedure © Chinese University, CSE Dept. Distributed Systems / 9 - 6

Simple Example • Press “Ctrl + F 5” to run the Web service which

Simple Example • Press “Ctrl + F 5” to run the Web service which includes two functions, i. e. , Hello. World and Add. • Click “Add” to invoke the Add function. Type some values into the form and click “Invoke”. © Chinese University, CSE Dept. Distributed Systems / 9 - 7

Simple Example • There a lot of publicly available Web services in the Internet,

Simple Example • There 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 “Website 1” and select “Add Web Reference…” • Type in the Web service address: http: //www. webxml. com. cn/Web. Services/Ip. Address. Search. Web. Service. asmx? wsdl • Click “Go” and click “Add Reference” to add the Web service into the project. © Chinese University, CSE Dept. Distributed Systems / 9 - 8

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

Simple Example • Add the following codes to the file “Service. cs”. • The above codes invoke an Internet Web service named Ip. Address. Search. Web. Service to get the geographic information from an IP address. • Press “Ctrl + F 5” to run the Web service, which includes three functions: © Chinese University, CSE Dept. Distributed Systems / 9 - 9

Simple Example • Click “IPAddress”. Type in an IP address and click “Invoke” to

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. © Chinese University, CSE Dept. Distributed Systems / 9 - 10