Cxf (2) Client development, WSDL Parsing

Source: Internet
Author: User

It is easy to write code, but you can understand the principles and processes.

Web Service is essentially an application of XML, and the message formats transmitted in the middle are all XML, which shields the differences between different programming languages.

That is to say, as long as the language that supports XML parsing supports Web service.

Nature of web service calls:

1) The client converts the called parameters to XML file fragments (soap messages, input)

2) The client transmits the document segment to the remote server over the network.

3) The server receives XML document fragments.

4) The server parses XML document fragments, extracts the data, and converts the data to the parameters required for calling.

5) server execution Method

6) obtain the return value of the method and convert it to an XML document segment (SOAP message, ouput)

8) the client receives and parses the file fragments to obtain the called data.

Three technical foundations of Web Service:

1. WSDL

1) Web Service Interface

1. types (Standard schema)

2. There are n methods (operations), and there are 2n messages, one input and one output

2) web service implementation

1. binding element -- N more detailed operation

2. Service -- specify the server address of the web service


2,

The client call is as follows:

The XML description we generated last time is at this address:

Http: // 10.5.82.195/hellows? WSDL

1. Use the cxf tool to generate client code.

In the bin directory of cxf, there is our generation tool wsdl2java. For convenience, you can put the bin directory under the PATH environment variable.

Create a new client project in eclipse.

Open CMD and go to the src directory of the project.

Run the following command: wsdl2java http: // 10.5.82.195/hellows? WSDL

The Code has been generated. Refresh the project.

2. Call

Automatically generated code. The package name is the same as that of the server. It is reasonable to say that the client does not know what package name is used by the server.

But remember, in the description file of the WSDL, the command space is named according to the package name. The client generates code based on the description file.

Of course, it doesn't matter what the package name is.

Creating a clienttest test class is also simple to call.

public class ClientTest {/** * @param args */public static void main(String[] args) {HelloWS factory = new HelloWS();Hello hello = factory.getHelloImplPort();System.out.println(hello.sayHello("dedede"));}}

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.