WebService的开发模版(Axis2_15环境).docx
-
资源ID:1894395
资源大小:175.19KB
全文页数:6页
- 资源格式: DOCX
下载积分:16金币
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
|
WebService的开发模版(Axis2_15环境).docx
WebService的开发模版(Axis2 1.5环境) Axis2已经升级到1.5了,下载地址: 两个包,bin是开发包,war是部署包。环境:axis2-1.5jdk1.5一、创建项目 导创建一个Java项目,项目结构如下图:Servicesrc pojo META-INF 二、导入axis2的包 解压缩axis2-1.5-bin.zip到一个目录下,然后直接引入axis2的jar包即可。也可以讲axis2的包复制到lib下。 三、创建服务 axis2服务的创建过程就是写Java类。这里创建一个最简单的Service,作为发布对象。 package pojo; /* * 测试Service * * author leizhimin 2009-8-4 15:48:13 */ public class SimpleService public String doSomething(String taskname) System.out.println("MyServiceImpl is calling doSomething with " + taskname + "!"); return taskname + "is finished!" 把创建好的SimpleService.class文件拷贝到axis的pojo下面 ,如果没有pojo文件夹则自己创建一个。四、描述服务 在项目的srcMETA-INF文件夹下面,创建services.xml,内容如下:<service name=" SimpleService " scope="application" targetNamespace=" <messageReceivers> <messageReceiver mep="http:/www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> <messageReceiver mep="http:/www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </messageReceivers> <parameter name="ServiceClass">pojo.SimpleService</parameter> </service> 服务名:SimpleService服务实现类:pojo.SimpleService 生成SimpleService.aar文件,目的是类文件可以带包名进行发布服务 1.cmd->进入到项目的“src”目录à执行下面命令-“jar -cvf SimpleService.aar META-INF”;五、部署服务将下载的axis2-1.5-war.zip解开,得到一个axis2.war,将其解压缩到tomcat的默认的web发布目录webapp下面,比如,在我机器上会产生F:apache-tomcat-6.0.20webappsaxis2的目录,目录下面就是axis2.war里面的内容。 然后,将生成的SimpleService.aar复制到F:apache-tomcat-6.0.20webappsaxis2WEB-INFservices下面。 八、启动tomcat,查看发布服务 浏览axis2的服务 点Services,查看所有的服务在点击服务连接,就可以查看wsdl了: 经过这样的测试后,服务发布算成功了。六、客户端服务package pojo;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;import .MalformedURLException;import .URL;import .URLConnection;import java.util.ArrayList;import java.util.Date;import java.util.HashMap;import java.util.Map;import java.util.Timer;import java.util.TimerTask;import javax.xml.namespace.QName;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.rpc.ServiceException;import org.apache.axis.client.Call;import org.apache.axis.client.Service;import org.apache.axis2.addressing.EndpointReference;import org.apache.axis2.client.Options;import org.apache.axis2.rpc.client.RPCServiceClient;public class RPCClient public static void main(String args) throws Exception try / 使用RPC方式调用WebService RPCServiceClient serviceClient = new RPCServiceClient(); Options options = serviceClient.getOptions(); / 指定调用WebService的URL EndpointReference targetEPR = new EndpointReference( "http:/localhost:8007/axis2/services/SimpleService"); options.setTo(targetEPR); / 指定getGreeting方法的参数值 Object opAddEntryArgs = new Object "2011-1-25测试" / 指定getGreeting方法返回值的数据类型的Class对象 Class classes = new Class String.class; / 指定要调用的getGreeting方法及WSDL文件的命名空间 QName opAddEntry = new QName("http:/pojo", "QueryCompany"); / 调用getGreeting方法并输出该方法的返回值 String xml =(String)serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes)0; System.out.println(xml); catch (Exception e) e.printStackTrace();