WebService definition : As the name implies is a web-based service. It uses the Web (HTTP) method to receive and respond to some kind of request from the external system. This allows for remote invocation.
WSDL –webservice Description language–web Service Description Language.
Explain where the service is-address, in XML form.
describe what method the service provides in XML form – how to invoke it.
A manual provided by the server to the client
a message format that constrains communication between the client and the server
SOAP-simple Object access Protocol (Simple Object Access Protocol)
Soap is used as an XML-based protocol for the transmission of data over the Internet.
SOAP = +xml data on the basis of HTTP.
SOAP is HTTP-based.
The composition of soap is as follows:
envelope– must be part of. appears as the root element of the XML.
headers– is optional.
body– is necessary. In the body section, the method that contains the server to be executed. And the data sent to the server.
First, the development of service-side procedures
1 // This annotation must be added when publishing a service with the JDK 2 Public class Personservice {3 4 Public string SayHello (string name) {5 return name + "Hello"; 6 }7 }
1 public class Publisher { 2 public static void main (string[] args) { 3 // first parameter: address of the Publishing service 4 // second parameter: Create an object for the service class 5 endpoint.publish ("Http://192.168.22.1:8099/hello", new Personservice ()); 6 } 7 }
Use Endpoint to publish Endpoint.publish ("Http://192.168.15.82:8098/hell", New Userserviceimpl ()); Note: The service class must have at least one method in service class WebService the JDK publishes the WebService service when the service class must need to add @webservice to the service class Method 1. Cannot be static * 2. Cannot be final JDK Support for WebService Publishing service classes with interfaces is not good, and the soap1.2 protocol is flawed
Second, the client calling program
Wsimport: Parameter:-s generate source code-p package name after generating code
Step: (1) Find an empty folder through the command line, switch to the empty folder directory execution: Wsimport-s. -P com.xxx.xx http://192.168.15.82:8099/hello?wsdl
(2) Copy the code to the client's project
(3) service-side invocation
1. Create a service Access Point collection Object Personserviceservice pss = new Personserviceservice ();
2. Get the service point binding class, use Get Plus port name (personserviceport), getpersonserviceport personservice PS = Pss.getpersonserviceport () ;
3. Call the service-side method String result = Ps.sayhello ("Zhangsan"); SYSTEM.OUT.PRINTLN (result);
WebService Basic use