First, Web Service Introduction
1. Basic concept of WEB service
Web service, also known as XML Web service WebService, is a lightweight, independent communication technology that can receive requests passed from the Internet or other systems on the intranet. is: Software services provided through SOAP on the web, described using WSDL files, and registered through UDDI.
XML: (extensible Markup Language) Extensible Markup Language. Temporary data processing for short-term, web-oriented network, is the basis of soap.
Soap: Simple Object access Protocol protocol. is the communication protocol for XML WEB Service. When a user finds your WSDL description document through UDDI, he can invoke one or more of the actions in the Web service that you set up by soap. SOAP is a specification for calling methods in the form of XML documents that can support different underlying interfaces, such as HTTP (S) or SMTP.
WSDL: (Web Services Description Language) A WSDL file is an XML document that describes a set of SOAP messages and how to exchange them. In most cases, it is automatically generated and used by the software.
UDDI (Universal Description, Discovery, and integration) is a new project primarily for Web service providers and users. Before a user can invoke a Web service, it is important to determine which business methods are included in the service, to find the called interface definition, and to prepare the software on the server side, and UDDI is a mechanism to guide the system through the description document to find the appropriate service. UDDI uses the SOAP message mechanism (standard xml/http) to publish, edit, browse, and find registration information. It uses XML format to encapsulate various types of data and send it to the registry or to the registry to return the required data.
2. Characteristics of XML Web service
1), cross-firewall communication
2), Application integration
3), business-to-business integration
4), software and data reuse
Second, Web Service Development
1. First create a Web service with the suffix. asmx in the project
2. Open the. cs file to see the automatically generated original code:
Using system;using system.collections.generic;using system.linq;using system.web;using System.web.services;namespace webserivce{//<summary>//Webservice_1/// </summary> [ WebService (Namespace = "http://tempuri.org/")] [webservicebinding (ConformsTo = wsiprofiles.basicprofile1_1) ] [System.ComponentModel.ToolboxItem (false)]//To allow the use of ASP. NET AJAX to invoke this Web service from a script, uncomment the following line. [System.Web.Script.Services.ScriptService] public class WebService_1:System.Web.Services.WebService {[ WebMethod] public string HelloWorld () {return ' Hello World ';}}}
3. Run the Web serivce file (you need to write down the URL address first)
4, re-create a project, we will visit the above Web services
Adding methods in Web Services
1 usingSystem; 2 usingSystem.Collections.Generic; 3 usingSystem.Linq; 4 using system.web; 5 using System.Web.Services; 6 7 namespace Webserivce 8 {9//< SUMMARY>10///Webservice_1 Summary description///</SUMMARY>12 [WebService (Namespace = "http://tempuri.org/")]13 [ WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]14 [System.ComponentModel.ToolboxItem (false)] 15//To allow the use of ASP. NET AJAX to invoke this Web service from a script, uncomment the following line. +//[system.web.script.services.scriptservice]17 public class WebService_1:System.Web.Services.WebService18 {webmethod]21 public string HelloWorld () {[] "Hello World", }25 [Web Method (Description = "Methods of summation")]27 public int Add (int num1,int num2)- {return num1 + num2;30 }31 }32}
5. Add a service reference in another project.
6. Next, you can invoke the Web service in the ASPX page
1 usingSystem; 2 usingSystem.Collections.Generic; 3 using System.Linq; 4 using system.web; 5 using System.Web.UI; 6 using System.Web.UI.WebControls; 7 8 NA Mespace firsttest 9 {Ten public partial class First:System.Web.UI.Page11 {protected void Page _load (Object sender, EventArgs e)- {}16 ///<SUMMARY>17////</SUMMARY>19// <param name= "Sender" ></param>20//<param name= "E" ></param>21 protected void button1_click ( Object sender, EventArgs e) ( {num1 = Convert.ToInt32 (this . txtnum1). Text), num2 = Convert.ToInt32 (this . txtnum2. Text); Firstwebservice.webservice_1soapclient a = new firstwebservice.webservice_1soapclient (); result = A.add (NUM1, num2); this.txtresult.Text = result. ToString (); }30 }31}
1 <%@ page language= "C #" autoeventwireup= "true" codebehind= "First.aspx.cs" inherits= "Firsttest.first"%> 2 3 <! DOCTYPE html> 4 5 nbsp;16 <asp:textbox id= "txtnum2" runat= "Server" width= "88px" ></asp:textbox>17 ; <asp:button id= "Button1" runat= "Server" onclick= "Button1_Click" text= "Calculation"/>18 19 <asp : TextBox id= "Txtresult" runat= "Server" width= "96px" ></asp:textbox>20 </div>22 </form>23 </body>24
Running the project enables addition operations in the Web service.
Web Service Learning