Web Service learning and webservice Learning

Source: Internet
Author: User

Web Service learning and webservice Learning

I,Web ServiceIntroduction

1. Basic concepts of Web Service

Web Service, also known as XML Web Service WebService, is a lightweight independent communication technology that can receive requests from other systems on the Internet or Intranet. Yes: The software services provided on the Web through SOAP are described using the WSDL file and registered through UDDI.

XML :( Extensible Markup Language) Extended Markup Language. Short-term-oriented temporary data processing and hichina network are the basis of Soap.

Soap: (Simple Object Access Protocol) Simple Object Access Protocol. Is the communication protocol of XML Web Service. After you find your WSDL Description document through UDDI, you can use SOAP to call one or more operations in your Web service. SOAP is a standard for calling methods in XML format. It supports different underlying interfaces, such as HTTP (S) or SMTP.

WSDL :( Web Services Description Language) the WSDL file is an XML document that describes a group 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 mainly for Web service providers and users. Before you can call a Web service, you must determine the business methods contained in the service, find the called interface definition, and compile software on the server, UDDI is a mechanism that guides the system to find the corresponding service based on the description document. UDDI uses the SOAP message mechanism (standard XML/HTTP) to publish, edit, browse, and find registration information. It uses XML format to encapsulate different types of data and sends the data to the Registration Center or the Registration Center to return the required data.

 

2. XML Web Service Features

1) Cross-firewall communication

2) Application Integration

3) B2B Integration

4) software and data Reuse

 

II,Web ServiceDevelopment

1. Create a Web service named. asmx in the project.

 

 

 

 

2. Open the. cs file and you will 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> // summary of WebService_1 /// </summary> [WebService (Namespace = "http://tempuri.org/")] [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] [System. componentModel. toolboxItem (false)] // to allow ASP.. net ajax calls this Web service from a script. uncomment the following lines. // [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 (write down the url address first)

 

4. recreate a project and we will access the web Service

Add method in web Service

1 using System; 2 using System. collections. generic; 3 using System. linq; 4 using System. web; 5 using System. web. services; 6 7 namespace WebSerivce 8 {9 // <summary> 10 // summary of WebService_1 11 /// </summary> 12 [WebService (Namespace = "http://tempuri.org /")] 13 [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] 14 [System. componentModel. toolboxItem (false)] 15 // to allow ASP. net ajax calls this from the script For Web Services, uncomment the following lines. 16 // [System. web. script. services. scriptService] 17 public class WebService_1: System. web. services. webService18 {19 20 [WebMethod] 21 public string HelloWorld () 22 {23 return "Hello World"; 24} 25 26 [WebMethod (Description = "summation method")] 27 public int Add (int num1, int num2) 28 {29 return num1 + num2; 30} 31} 32}

 

 

5. Add service references to another project.

 

6. You can call the web service on the aspx page.

 

1 using System; 2 using System. collections. generic; 3 using System. linq; 4 using System. web; 5 using System. web. UI; 6 using System. web. UI. webControls; 7 8 namespace FirstTest 9 {10 public partial class First: System. web. UI. page11 {12 protected void Page_Load (object sender, EventArgs e) 13 {14 15} 16 /// <summary> 17 // calculate 18 /// </summary> 19 /// <param name = "sender"> </param> 20 /// <param name = "e"> </param> 21 protected void button#click (object sender, eventArgs e) 22 {23 int num1 = Convert.ToInt32(this.txt num1.Text); 24 int num2 = Convert.ToInt32(this.txt num2.Text); 25 26 FirstWebService. webService_1SoapClient a = new FirstWebService. webService_1SoapClient (); 27 int result =. add (num1, num2); 28 this.txt result. text = result. toString (); 29} 30} 31}

 

 

1 <% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "First. aspx. cs" Inherits = "FirstTest. First" %> 2 3 <! DOCTYPE html> 4 5 

 

 

Run the project to implement addition operations in web service.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.