"WebService" uses command Wsimport to build WebService client

Source: Internet
Author: User
Tags wsdl

Wsimport Command Introduction

In the Bin folder of the JDK, there is a wsimport.exe, which generates the corresponding class file based on the WSDL file, and then uses these class files to invoke the WebService provider as if it were a local class. The tool can be used for non-Java servers, such as WebService written in C #, which generates a Java client implementation through Wsimport . For the use of commands, we take the open Chinese characters and traditional characters to convert the Web Service interface As an example, as follows:

Use the following command at the command prompt:

Wsimport-keep-p com.zhj2f.client http://www.webxml.com.cn/WebServices/ TRADITIONALSIMPLIFIEDWEBSERVICE.ASMX?WSDL
Command parameter description (here is a direct introduction to the more commonly used): |  -D: Generate Directory of class files for client execution classes |  -S: Generate a directory of source files for client execution classes | -P: Define the package name of the generated class using the Wsimport command, we can get the corresponding code file, copy it to your project, and use it, as shown in the following directory tree structure:Test: Create a new project, and copy the Com.zhj2f.client package to the project file, write the test file Test.java, the code is as follows:
 Packagetest;ImportCom.zhj2f.client.TraditionalSimplifiedWebService;ImportCom.zhj2f.client.TraditionalSimplifiedWebServiceSoap; Public classTest { Public Static voidMain (String args[]) {traditionalsimplifiedwebservice Tsws=NewTraditionalsimplifiedwebservice (); Traditionalsimplifiedwebservicesoap TSS=Tsws.gettraditionalsimplifiedwebservicesoap (); String Res= Tss.totraditionalchinese ("Who am I?"));            System.out.println (RES); }}

Of course we can also use the same method as above to invoke the open WebService interface provided by the weather forecast , except that the weather forecast interface is a little different. If we use Wsimport to survive a Java file through a WSDL address, an error will be encountered. Because the WSDL contains references such as ref = "S:schema". And JAXB is not supported. So manually download the WSDL (that is, save the page as) and make the changes and then generate the Java file.

  Modify the method to: Change all <s:element ref= "S:schema"/> to <s:any minoccurs= "2" maxoccurs= "2"/>, and delete <s: any/>.

  Then the Java file is generated by Wsimport, and it can be used normally.

Resources:

[1] http://www.cnblogs.com/simle/archive/2011/11/03/2233417.html

[2] http://blog.csdn.net/lun379292733/article/details/18035915

[3] Common Web service Rollup

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.