Ultra-Streamlined WebService example

Source: Internet
Author: User
Tags soap wsdl

Look at the online a lot of examples of webservice, basically for beginners are ambiguous foggy, now, I will be on the web about webservice refined out, through a simplest use and convenient example, tell everyone what is WebService.

Simply put, WebService is a remote call technology, also called XML Web Service WebService, is a lightweight, independent communication technology that can receive requests that are passed from other systems on the Internet or 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.

How to publish a webservice:

1. Create a Web project

For simplicity, I've created three classes, an interface, an interface implementation class, and a publishing class (the Main method). Specific as follows:

This is the WebService interface, which defines a method for SayHello (String name)

Remember to add @webservice annotations to the class

@WebMethod note declares that this method is a method to be published.

This class is an implementation class for the WebService interface, which describes the method body of the SayHello (String name) method.

Finally we run the main method in the Webservicepublish class on the server side of the "console print out the Publish WebService success!" "Enter the address?wsdl that we defined in the Webservicepublish class in the browser(be sure to add WSDL), the browser is shown below, then we have this webservice published successfully.

Next, let's look at how the client calls ( This is also the most miscellaneous step of the version, most people understand before, but in this case it's just crazy)

First we create a CLIENT11 client project, and then we call cmd through the Win+r key combination, enter the src path in cmd wsimport-s our project,-keep the WebService address we publish for example:

Then go to eclipse and refresh our project and you'll find that the system automatically helps us generate many classes.

Of course, WSClient is a test class of a client that I wrote myself after the system was built.

Let's take a look at how this test class is written:

After running the console output is as follows:

You can see that ' Hahahaha ' is written on the server, so this simple and useful WebService server client is done.

Ultra-Streamlined WebService example

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.