加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

myeclispe8.5 开发webservice

发布时间:2020-12-17 00:30:27 所属栏目:安全 来源:网络整理
导读:1、下载所需要的ja包来搭建环境: ??????? 需要的jar包有org.apache.axis2.eclipse.service.plugin_1.6.2.jar、org.apache.axis2.eclipse.codegen.plugin_1.6.2.jar、axis2-1.6.2-bin.zip、axis2-1.6.2-war.zip ?????? 将前两个jar包解压放到C:Program File
1、下载所需要的ja包来搭建环境:

??????? 需要的jar包有org.apache.axis2.eclipse.service.plugin_1.6.2.jar、org.apache.axis2.eclipse.codegen.plugin_1.6.2.jar、axis2-1.6.2-bin.zip、axis2-1.6.2-war.zip

?????? 将前两个jar包解压放到C:Program FilesGenuitecMyEclipse 8.5dropins中,重新打开myeclipse8.5,file---new----other下出现axis2 wizard2 环境搭建成功;

2、将axis2-1.6.2-war.zip解压,将axis2.war部署到tomcat的webapp文件夹中,启动tomcat,这时会在webapp出现axis2文件夹;

3、开发webservice 服务端:

?????? 创建一web项目:SayHello,

????? 在com包下创建一个类:Hello.java;

?

public class Hello {
	public String helloWorld(String name){
		return "helloworld "+ name;
	}

}

4、创建wsdl文件:

??????? file--new---other---axis2 code generator---->next? 选中generator a wsdl form a java source file,

?????? 在Fully qualified class name 中填写类的名称(包含包的名称如com.Hello),点击add folder添加classes路径即

?????? SayHello项目下的web-info下的classes文件夹这个路径;然后点击next ,为.wsdl文件创建一个名称,点击next

???? 到此为止wsdl文件创建完成;

5、根据wsdl文件创建一个:

??? file---new---other----axis2 service archiver----next? 在工作目录中找到SayHello项目的classes文件,点next

? 然后选择select wsdl 选择上面创建的wsdl文件,并将要生成的arr文件的存放路径指定为WEB-INF下;

?? 到此为止webservice创建完成,将创建的aar文件放到tomcat的webappsaxis2WEB-INFservices中重启tomcat这是发布的服务的访问就可以被访问;

6、创建一个调用webservice 服务中的方法:

??????

public class Client  {
	public static void main(String[] args) throws Exception{
		 //  使用RPC方式调用WebService
		 RPCServiceClient serviceClient = new RPCServiceClient();
		 Options options = serviceClient.getOptions();
		//  指定调用WebService的URL
		 EndpointReference targetEPR = new 
		 	EndpointReference("http://localhost/axis2/services/service");  
		//  指定method方法的参数值
		 String name="lid";
		 Object[] opAddEntryArgs = new Object[] {name};
		//  指定method方法返回值的数据类型的Class对象
		 Class[] classes = new Class[] {String.class};
		//  指定要调用的method方法及WSDL文件的命名空间
		 QName opAddEntry = new QName("http://ws.apache.org/axis2","helloWorld");
		//  调用method方法并输出该方法的返回值
		 System.out.println(serviceClient.invokeBlocking(opAddEntry,opAddEntryArgs,classes));
	}
}

到此为止环境的搭建 以及一个小demo完成;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读