WebService Basic use

Source: Internet
Author: User
Tags soap wsdl

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

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.