POJO,Plain Old Java Object,简单的Java对象。
public class Hello {
public String sayHello(){
return "hello";
}
public String sayHelloToPerson(String name){
if(name==null){
name = "nobody";
}
return "hello,"+name;
}
}编译Hello.java得到Hello.class,并放到<Tomcat安装目录>\webapps\axis2\WEB-INF\pojo\目录中(如果没有pojo目录,则建立该目录)。现在我们已经成功将Hello类发布成了WebService。在浏览器地址栏中输入如下的URL:http://localhost:8080/axis2/services/listServices ,得到下图结果。
链接 http://localhost:8080/axis2/services/Hello?wsdl 得到wsdl,Web Services Description Language,Web 服务描述语言。本质是xml。
链接
http://localhost:8080/axis2/services/Hello?xsd 得到xsd,Xml Schema Definition,xml 模式定义,本质是xml。
a ) http请求得到xml
b) java客户端使用
import org.apache.ws.axis2.HelloStub;
import org.apache.ws.axis2.HelloStub.SayHello;
import org.apache.ws.axis2.HelloStub.SayHelloResponse;
import org.apache.ws.axis2.HelloStub.SayHelloToPerson;
public class StubClient
{
public static void main(String[] args) throws Exception
{
HelloStub stub = new HelloStub();
SayHello obj=new SayHello();
SayHelloToPerson obj2=new SayHelloToPerson();
obj2.setName("XiaoMing");
SayHelloResponse response=stub.sayHello(obj);
String str=response.get_return();
System.out.println(str);
System.out.println(stub.sayHelloToPerson(obj2).get_return());
}
}
/*
hello
hello,XiaoMing
*/原文:http://blog.csdn.net/chuchus/article/details/44258899