myeclispe8.5 开发webservice

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 Files\Genuitec\MyEclipse 8.5\dropins中,重新打开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的webapps\axis2\WEB-INF\services中重启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完成;


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bzuld

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值