How to implement JAVA WebService __java

Source: Internet
Author: User

WebService implementation: 1. Use the Java JDK Web Service API to implement 2. Use CXF to combine spring

I. Using JDK Web Service API methods

① creates an interface that uses the @webservice () annotation to indicate that the Java interface is an interface for the WebService service

② creates an implementation class that implements the interface, and also uses @webservice (Endpointinterface indicates an access point interface) annotation to indicate that the Java class is the implementation class for the WebService service interface.


How to create a client in the same project

URL: Create URL object from URL

QName: Creates a QName object based on the namespace and the name of the service in the WSDL file

Service: Creating Service objects

Obtaining service Interfaces for server-side publications based on the service object

Invoke the method provided by the service interface


Generating client code using DOS commands

-D: Specifies the file directory where client code is generated

-keep: Generating Source code files

-verbose: Generate detailed information

-P: Specifies the package name of the generated code file


Two, use spring and cxf combine to realize webservice

Download the compressed package

To import a jar package from a compressed package into a project

1. Create a Service interface class

2. Create the implementation class for the service interface


To configure the contents of the Spring.xml file:

Configuring Web.xml Files

Add Project to Tomcat, start service, enter in browser

HTTP://127.0.0.1:315/CXFWEBSERVICE/SERVICES/MYSERVICE?WSDL IP Address + port number + project name +CXF URL map configured in Web.xml + Posted service address

The format for saving the WSDL file file is XML

In DOS, switch directories to the directory below

Enter the following command:

-P: Specifies the package name of the build file

-D: Specifies the directory of the generated file

-verbose: Generate detailed information

"C:\myService.xml" is the path to the saved Wsdl.xml


Create a client project to copy the generated files into the project

The structure of the project is:

Methods to invoke service interfaces provided by the service side

The following results are obtained:


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.