1.在官网下好Axis2的包
2.打开eclipse,点击菜单栏Windows- preferences-Axis2 preferences-Axis2 Runtime-browse..选择刚才下好并解压好的包。注意:如果位置正确,下方会出现Axis2 runtime loaded successfully
4.在Tomcat上部署项目,不会的请自行百度。在浏览器输入http://localhost:8080/WebServiceTest1/axis2-web/
点击vilidate,若出现如图绿字,即为部署成功
5.点击 Administration ,在右边登陆,账号admin,密码axis2。这是一个管理平台。
6.在项目SRC下新建一个类
public class helloworld { public helloworld(){ } public String sayHello(String name){ return name+"hello"; } }右击目录树上的这个类Web Service-Create Web Service
把左边上面黄色和温度计差不多的拉倒最上面,下面的拉倒倒数第二个,点击右边红色也就是第二排的,进去后选择Apache Axis2。点击ok,点击publish webservice,一路Next,会出现一个 launch,点击它。
11.在点击刚才的那个管理平台右边的黄色地方,会看到发布的服务方法
11.在自动创建的client类中建一个简单的类进行测试
package service; import javax.xml.namespace.QName; import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.client.Options; import org.apache.axis2.rpc.client.RPCServiceClient; public class Test { public static void main(String[] args) { try { RPCServiceClient client = new RPCServiceClient(); Options options = client.getoptions(); String address = "http://localhost:8080/WebServiceTest1/services/helloworld"; EndpointReference epf = new EndpointReference(address); options.setTo(epf); QName qname = new QName("http://service","sayHello"); Object[] result = client.invokeBlocking(qname,new Object[] { "jack" },new Class[] { String.class }); System.out.println(result[0]); } catch (Exception e) { System.out.println(e.getMessage()); } } }出现如图结果
13.还可以用另一种更简单的方法测试,在浏览器中输入http://localhost:8080/WebServiceTest1/services/helloworld/sayHello?name=jack,即可测试,如图
到此为止结束。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。