Build WebService client using command Wsimport

Source: Internet
Author: User

Server: See my previous blog post (Java calls the WebService interface using Xfire)

Client: 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.

Use the following command at the command prompt: Wsimport-keep-p com.demo.client http://localhost:8080/Demo/services/MyService?wsdl

Command parameter Description:

-D: Generate Directory of class files for client execution classes

-S: Generate a directory of source files for the client execution class

-P: Define the package name of the generated class

For additional command parameters, please refer to: http://download-llnw.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html

After using the Wsimport command, we can get the following code file:

  The current directory on the command line

|--com

|--demo

|--client

|--example.java

|--exampleresponse.java

|--myservice.java

|--myserviceporttype.java

|--objectfactory.java

|--package-info.java

You can copy the above files to your project and use them.

Test: Create a new project, and copy the Com.demo.client package to the project file, write the test file Test.java, the code is as follows:

Package Com.demo.wsimport;public class Test {/** * @param args*/public static void Main (string[] args) {        TODO auto-generated Method Stub myservice Server = new MyService ();        Myserviceporttype SPT = Server.getmyservicehttpport ();    System.out.println (spt.example ("Hello")); }}

Build WebService client using command Wsimport

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.