preface

To put it simply, WebService is a remote call technology, also called XML WebService. Webservice is a lightweight independent communication technology that can receive requests from other systems on the Internet or Intranet. Yes: Software services provided on the Web through SOAP, described using WSDL files and registered through UDDI.

A simplified example of a Webservice

XML

XML :(Extensible Markup Language). Soap is based on short-term temporary data processing and universal network.

Soap

Soap :(Simple Object Access Protocol). Is a communication protocol for XML Web Services. When a user finds your WSDL description document via UDDI, he can invoke one or more operations in your Web service via SOAP. SOAP is a specification for invoking methods in the form of XML documents that can support different low-level interfaces, such as HTTP(S) or SMTP.

WSDL

WSDL :(Web Services Description Language) the WSDL file is an XML document that describes a set of SOAP messages and how they are exchanged. In most cases, it is automatically generated and used by software.

How do I publish a WebService?

1. Create a Web project

Three classes were created

To keep things simple, I created three classes: an interface, an interface implementation class, and a publishing class (the main method). Details are as follows:

This is the WebService interface

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

Remember to annotate the class with @WebService

The @webMethod annotation declares that the method is the one to publish. This class implements the WebService interface and specifies the body of the sayHello(String Name) method.

WebService interface implementation class

This class implements the WebService interface and specifies the body of the sayHello(String name) method.

conclusion

Finally, on the server side, we run the main method of the WebServicePublish class. “Enter the address we defined in the WebServicePublish class in the browser? WSDL (be sure to add WSDL), the browser displays the following, and our WebService is published successfully.

Client side call

Now, let’s look at how the client calls (this is also the most complicated step in the version, most people are familiar with this, but it is completely confused by this step).

Create a client11 client project

First we create a client11 client project, then we use Win+R to call up CMD, enter wsimport -s SRC path of our project -keep the webService address we publish for example:

Refresh our project in Eclipse

Then go to Eclipse and refresh our project, and you’ll see that the system automatically generates a lot of classes for us.

Of course, WSclient is a client test class that I wrote after the system was generated

How do I write a test class

After running, the console output is as follows:

It can be seen that ‘hahahaha’ is written in the server, so this is our simple and practical webService server client complete.

Like xiaobian to share the article can like attention oh, share technology on the way thank you for your company!

More than 400 pages of PDF documents have been compiled for more than 1000 Java interview questions from different companies. There are still hundreds of pages of Java core knowledge PDF to get