Use Eclipse Plugin of xfire to generate web service client

Source: Internet
Author: User

Original article address:

Http://blog.csdn.net/igate/archive/2008/04/12/2286147.aspx

 

Coding environment: Eclipse SDK 3.2.2, Tomcat5.5.20, XFire-1.2.6.
Body:
There are multiple methods to generate a web service client using xfire. Eclipse Plugin provides Eclipse support for XFire's WSDL-> Code generator, which requires Eclipse 3.2 and Java 5. Here we use Eclipse Plugin to generate client code based on the wsdl file address, and we only need to write a few lines of code to call the web service. The steps are as follows:
Step 1: Install the plug-in.
Open the Help menu of Eclipse, select "Software Updates", and then select "Find and Install ."
Select Search for new features to install and click Next
Select "Create New Remote Site", enter "XFire" in name, and enter the http://dist.codehaus.org/xfire/update/ in eclipse update site
Select OK
Select Finish.
Note that after completing the above operations, eclipse needs to download and install plug-ins. The length of time depends on the speed of the network. Please be patient and restart eclipse when the installation is complete.
Step 2: Use the plug-in.
Create a java project XFireProject, select File> New> Other, select Code generation from WSDL document in the XFire folder, and open the Code generation wizard, as shown in figure 2.

Fill in http: // localhost: 8080/WSProject/services/HelloService in the address bar of the WSDL? In the wsdl and Output directory columns, click the Browse button and select the newly created Project XFireProject. These two items are required. You can select an existing package name from the package column. If you do not specify this option, the code generator will create one based on the target wsdl namespace.
After that, we can see that the XFire class library is added to the project and some classes generated under the package. Make sure that the Tomcat server of IDE is enabled.
At this point, before calling the service, there is an important step to bring up the Properties configuration window from the shortcut menu of the XFireProject project, select the XFire item in the left column, all the class libraries related to XFire running are listed on the right. As shown in figure 3, some class libraries are selected. These class libraries are required to call this service.

All the configurations have been completed, and finally the code is compiled to complete the call. The Code is as follows:

1 package wsClient;
2
3 import hao. HelloServiceClient;
4 import hao. HelloServicePortType;
5
6 public class Invoke {
7
8 /***//**
9 * This method calls the web service and returns the service execution result.
10 * @ param yourName
11 * @ return
12 */
13 public static String invokeServiceNow (String yourName)
14 {
15 HelloServiceClient service = new HelloServiceClient ();
16 HelloServicePortType port = service. getHelloServiceHttpPort ();
17 return port. sayHello (yourName );
18}
19 /***//**
20 * @ param args
21 */
22 public static void main (String [] args ){
23 // TODO Auto-generated method stub
24 String MyName = "xshy ";
25 System. out. println (Invoke. invokeServiceNow (MyName ));
26}
27}
28

The final output result of the program running is "xshy, hello !".
Note: Tomcat must be enabled when running the calling program.

References:
Using XFire to develop WebService in Eclipse
Http://xfire.codehaus.org/User%27s+Guide

 

This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/igate/archive/2008/04/12/2286147.aspx

 

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.