Java calls the WSDL interface

Source: Internet
Author: User
Tags wsdl

Prerequisite: ① has provided a WSDL interface ② the interface can be called normally
There are two ways of doing this:
1. Use CXF's Wsdl2java tool to generate a local class (using the local class).
2. Call the Remote Web service method: Create a client to invoke the interface remotely.
Because the second way, you need to be familiar with WSDL, not in-depth understanding of the operation is not good, mainly the first way.

The main steps for generating a local class using CXF's Wsdl2java tool are as follows:
1, install the JDK environment (JDK version is 1.6, the following will be error JDK6 maximum support only ws2.1 specification version)
2, download APACHE-CXF release package, download cxf:http://cxf.apache.org/download.html currently the latest version is 3.1.7, unzip the release package, set the Cxf_home, and add%cxf_home%/ Bin to PATH environment variable.
3, the cmd command line input wsdl2java-help, has the normal prompt to indicate that the environment has been correctly configured.
4. CMD Run command: wsdl2java-encoding utf-8-D D:\javalib\web http://m.zsjsjy.com/services/resource?wsdl
(Path to WSDL)
-encoding indicates that the generated Java file encoding format is utf8,-d and the code generation path is D:\javalib\we. Class that will be generated for use at the current path of the Run command after running
5. Import the generated class into the project. General Service is called Xxxservice, this is the interface file we want to use


The problems encountered in the above process:
1.
Because the JDK is version 1.6, causing the download of the APACHE-CXF release package to use error, this is CXF and JDK jar package conflict caused!
Downloaded the old version of the Apache-cxf-2.6.12.zip, checked some information, insurance, and then replaced the JDK 1.7,
If also reported is wrong, under the jdk1.7 folder under the JRE under the Lib file to create a endorsed folder (D:\java\jdk1.7.0_16\jre\lib\endorsed),
The three 2.2jar packets from JAXB in APACHE-CXF were copied to endorsed, and the local Java classes were successfully produced.
2.
After the successful generation of Java file Import project, adjusted the Java error in the package file, the result Serviece class or there is a constructor error, note that the need to jaxws2.2 to regenerate.
I checked the information and said it could not compile properly because of the conflict between jax-ws2.2 statute and JAVA6. However, the program cannot be compiled with JAVA5 only, so the Jax-WS protocol version needs to be reduced.
Workaround: Execute command: wsdl2java-frontend jaxws21-d D:\JAVALIB\CN http://m.zszsjsjy.com/services/resource?wsdl
Rebuild to resolve.
3.
Interface call test times wrong, Exception in thread "main" org.apache.cxf.service.factory.ServiceConstructionException
The reason is to generate the interface Java class, the namespace path is its original default, and I put in the project when the class path is now. Workaround:
A custom-p path rebuild is required:
Wsdl2java-frontend jaxws21-encoding Utf-8-P Cn.teacheredu.app.projectconfigcenter.proj.module.screen.tlogin.zswebservice-d D:\JAVALIB\CN/HTTP m.zszsjsjy.com/services/resource?wsdl

Java calls the WSDL interface

Related Article

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.