WebService working principle and examples

Source: Internet
Author: User
Tags soap wsdl

Basic concepts 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.

Invocation principle

  

  Implementing a complete Web service consists of the following steps:

The Web service provider designs the implementation Web service and publishes the correct Web service through the Web Service Broker and registers with the UDDI registry; (publish)

A Web service requester requests a specific service from a Web service broker, who queries the UDDI registry on request, and finds the service that satisfies the request for the requestor;

The Web service mediator returns to the Web service requester the Web Service description information that satisfies the condition, which is written in WSDL and can be read by various machines that support Web services;

Generate the corresponding SOAP message from the description information returned by the Web service mediator and send it to the Web service provider for the invocation of the Web service; (binding)

The Web service provider executes the corresponding Web service by SOAP message and returns the result of the service to the Web service Requester. Binding

Invocation mode

Web Service Instance

1. Create a Web service server

Create a Web service interface that defines a method for Sayhi (String Name) that must be added @WebService annotations on the class, @WebMethod note declares that this method is to be published

Create a Web Service interface implementation class, stating the method body of the Sayhi (String Name) method

Create a publishing class (main METHOD) and publish the Web service

Run ServiceMain so the release is Successful.

To verify this, Enter the address?wsdl defined in the Webservicepublish class in the browser (be sure to add wsdl), the browser is displayed as follows, then our WebService is published Successfully.

Client Calls

To create a wsclient project

In the cmd window, enter wsimport-s the src path of our Project-keep the WebService address we published for Example:

Wsimport-s C:\Users\Administrator\workspace\WSClient\src-keep http://127.0.0.1:8091/test/hello?wsdl

Wsimport is a jdk-brought tool that generates client-side calling code based on a WSDL document. of course, the Java code will be generated on the client, regardless of what language the Server-side WebService is written in. It doesn't matter what the server is written About.
Wsimport.exe is located in the Java_home\bin directory.

To refresh our project in eclipse, you will find that the system automatically helps us generate many classes

Create a test class for a client

After running the console output is as Follows:

WebService working principle and examples

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.