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(new
// QName("", "username"),String.class,"dfdfs");
//直接调用factory.createUserUsername("dfdfs")返回JAXBElement类型
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());
}
}