XFire根据WSDL生成客户端程序
1.更新The XFire Eclipse plugin
The XFire Eclipse plugin provides Eclipse support for XFire's WSDL->Code generator. It requires Eclipse 3.2 and Java 5.
Installing the Plugin
To install the Eclipse XFire plugin:
go to the Help menu, select "Software Updates" and then select "Find and Install."
Select "Search for new features to install" and click Next.
Select "Create New Remote Site" and enter "XFire" as the name and http://dist.codehaus.org/xfire/update/ as the eclipse update site.
Select OK.
Select Finish
2.安装好后出现
3.新建一个web project,将
生成的client程序放到源文件夹中,
不要加myeclipse中的XFire库文件,因为客户端运行所导入的xfire1.2.6和服务器端的xfire1.2.5版本不一致,导致以上问题。
直接下载xfire-1.2.6,把其中的lib加到project就好了。
4.最后写个测试程序就好。
import com.kuaff.xfire.samples.MathServiceClient;
import com.kuaff.xfire.samples.MathServicePortType;
public class Test {
public static void main(String[] args) {
MathServiceClient client = new MathServiceClient();
MathServicePortType MathService = client.getMathServiceHttpPort();
// 调用服务
long result = MathService.add(1, 2);
System.out.println("结果:" + result);
}
}
当有参数传递时,
import test.HelloServiceClient;
import test.HelloServicePortType;
import test.ObjectFactory;
import test.User;
import javax.xml.namespace.QName;
public class TestAddress {
public static void main(String[] args) {
HelloServiceClient client = new HelloServiceClient();
HelloServicePortType HelloService = client.getHelloServiceHttpPort();
// 当要传递参数时,调用ObjectFactory中的公用方法,而不用自己还要
//new JAXBElement<String>(new
// QName("http://test", "username"),String.class,"dfdfs");
//直接调用factory.createUserUsername("dfdfs")返回JAXBElement<String>类型
ObjectFactory factory=new ObjectFactory();
User user=factory.createUser();
user.setPassword(factory.createUserPassword("afdsafsd"));
user.setUsername(factory.createUserUsername("dfdfs"));
// 调用服务
//由JAXBElement转化为String,调用getValue();
System.out.println(HelloService.getUser(user).getUsername().getValue());
}
}
1.更新The XFire Eclipse plugin
The XFire Eclipse plugin provides Eclipse support for XFire's WSDL->Code generator. It requires Eclipse 3.2 and Java 5.
Installing the Plugin
To install the Eclipse XFire plugin:
go to the Help menu, select "Software Updates" and then select "Find and Install."
Select "Search for new features to install" and click Next.
Select "Create New Remote Site" and enter "XFire" as the name and http://dist.codehaus.org/xfire/update/ as the eclipse update site.
Select OK.
Select Finish
2.安装好后出现
3.新建一个web project,将
生成的client程序放到源文件夹中,
不要加myeclipse中的XFire库文件,因为客户端运行所导入的xfire1.2.6和服务器端的xfire1.2.5版本不一致,导致以上问题。
直接下载xfire-1.2.6,把其中的lib加到project就好了。
4.最后写个测试程序就好。
import com.kuaff.xfire.samples.MathServiceClient;
import com.kuaff.xfire.samples.MathServicePortType;
public class Test {
public static void main(String[] args) {
MathServiceClient client = new MathServiceClient();
MathServicePortType MathService = client.getMathServiceHttpPort();
// 调用服务
long result = MathService.add(1, 2);
System.out.println("结果:" + result);
}
}
当有参数传递时,
import test.HelloServiceClient;
import test.HelloServicePortType;
import test.ObjectFactory;
import test.User;
import javax.xml.namespace.QName;
public class TestAddress {
public static void main(String[] args) {
HelloServiceClient client = new HelloServiceClient();
HelloServicePortType HelloService = client.getHelloServiceHttpPort();
// 当要传递参数时,调用ObjectFactory中的公用方法,而不用自己还要
//new JAXBElement<String>(new
// QName("http://test", "username"),String.class,"dfdfs");
//直接调用factory.createUserUsername("dfdfs")返回JAXBElement<String>类型
ObjectFactory factory=new ObjectFactory();
User user=factory.createUser();
user.setPassword(factory.createUserPassword("afdsafsd"));
user.setUsername(factory.createUserUsername("dfdfs"));
// 调用服务
//由JAXBElement转化为String,调用getValue();
System.out.println(HelloService.getUser(user).getUsername().getValue());
}
}