首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Java创造WebService服务及客户端实现

2013-10-15 
Java创建WebService服务及客户端实现WebService是一种服务的提供方式,通过WebService,不同应用间相互间调

Java创建WebService服务及客户端实现

       WebService是一种服务的提供方式,通过WebService,不同应用间相互间调用变的很方便,网络上有很多常用的WebService服务,如:http://developer.51cto.com/art/200908/147125.htm,不同的语言平台对WebService都有实现,Java的WebService实现,比较流行的有Axis2、Jaxws,本文介绍的是Axis2。

       Axis2下载和部署

       Axis2是Apache开发的一个开源项目,再次感叹Apache的伟大!

       下载地址:

       http://mirror.bit.edu.cn/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-war.zip

       将其内axis2.war解压到<Tomcat安装目录>/webapps下,启动Tomcat,war包会自动解压,

       访问http://localhost:8080/axis2/,如果看到欢迎主页,则说明部署成功。

       配置Axis2

       <Tomcat安装目录>/webapps/axis2/WEB-INF/conf/axis2.xml,配置其内两个属性,以便调试。

       我打的名字是server.jar,更改后置为aar,所以最后是server.aar,Axis2建议使用aar发布WebService,

       将server.aar放到<Tomcat安装目录>/webapps/axis2/WEB-INF/services下,访问http://localhost:8080/axis2/services/listServices,

       多出了一个CalculateService,说明发布成功。

package webservice.client.test;import java.rmi.RemoteException;import webservice.client.test.RandomFontsWebServiceStub.ArrayOfString;import webservice.client.test.RandomFontsWebServiceStub.GetChineseFonts;public class ThirdClient {/** * @param args * @throws RemoteException  */public static void main(String[] args) throws RemoteException {RandomFontsWebServiceStub stub = new RandomFontsWebServiceStub();GetChineseFonts getChineseFonts = new GetChineseFonts();getChineseFonts.setByFontsLength(10);// 免费使用有限制,最多8个ArrayOfString result = stub.getChineseFonts(getChineseFonts).getGetChineseFontsResult();for(String str : result.getString()) {System.out.println(str);}}}

       (完)

1楼kyfxbl昨天 23:25
强烈建议楼主了解一下cxf,以及cxf和spring集成的方式。你会发现这篇文章提到的方法是多么繁琐
Re: ghsau昨天 23:35
回复kyfxbln繁琐吗?还好吧,你不觉得学习要有个过程吗
Re: kyfxbl4分钟前
回复ghsaun学习当然有过程,其实你还可以去学习纯手工解析soap

热点排行