论坛首页 Java企业应用论坛

Java 中利用 axis2 进行webservice 客户端编写

浏览 7097 次
精华帖 (0) :: 良好帖 (1) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2013-05-29  

 

Java 中利用 axis2  进行webservice 客户端编写

 

 

 

1 安装axis2客户端

 

 

 

下载客户端本文下载的是 1.6.2 下载地址是北京交通大学的apache镜像

 

地址http://mirror.bjtu.edu.cn/apache/axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip

 

 

 

下载完成后解压下图所示



 

2 java客户端的编写

 

Axis2提供脚本生成客户端代码,脚本文件在bin目录下



 

 

执行脚本生成客户端

 

2.1 启动cmd

 



 

 

 

 

2.2生成客户端包代码命令
WSDL2Java -uri wsdl
文件全路径 -p 包名 -d xmlbeans -s -o 生成的java代码存放路径

WSDL2Java
命令参数说明:
-uri
指定*.wsdl文件,可以带具体路径;
-p
指定生成代码的包名
-d xmlbeans
使用不同的数据绑定方法;
-o
指定生成代码放置的路径;
-ss
表示要生成服务端代码;
-ssi
表示要生成代码中,先生成接口类,再生成实现类;

 

 

 

常用命令格式

 

wsdl2java -uri  http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl  -p com.jshand.axis2.client  -s -o d:\axisclient

 

 

红色部分可以改变

 



 

 

执行完成后

 

在指定目录后即生成客户端代码

 



 

 

可以直接粘贴到项目中进行使用

 

 

 

3 客户端代码的使用

 

                  

//生成客户端stub示例
		WeatherWSStub stub = new WeatherWSStub();
		//生成webservice一个方法的请求示例
		WeatherWSStub.GetRegionProvince  regionProvince =  new WeatherWSStub.GetRegionProvince();
		//调用stub的获取方法属性,返回一个****Response
		GetRegionProvinceResponse regionProvinceResponse = stub.getRegionProvince(regionProvince);
	
	//从****Response取得结果,此处根据需要进行调整
		ArrayOfString arrayOfString = regionProvinceResponse.getGetRegionProvinceResult();
		
		String[] strings = arrayOfString.getString();

 

 

  • 大小: 37.4 KB
  • 大小: 31.2 KB
  • 大小: 28.8 KB
  • 大小: 57.4 KB
  • 大小: 12.8 KB
   发表时间:2013-06-04  
这个是同步调用,异步的方式更普遍
0 请登录后投票
   发表时间:2013-06-04  
islove1945 写道
这个是同步调用,异步的方式更普遍

嗯,确实是这样的, 这里指进行了简单的介绍,稍后我会把异步的方式加上
0 请登录后投票
   发表时间:2013-06-05  
引用
wsdl2java -uri  http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl  -p com.jshand.axis2.client  -s -o d:\axisclient 


axis2的可以用?
为什么CXF同样的wsdl2java解析WeatherWS.asmx报错?

D:\temp>apache-cxf-2.7.3\bin\wsdl2java -p my -d . http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl


错误提示:
引用

WSDLToJava Error: http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl [15,19]: undefined element declaration
's:schema'
http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl [61,19]: undefined element declaration 's:schema'
http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl [101,13]: undefined element declaration 's:schema'
0 请登录后投票
   发表时间:2013-06-05  
JDK1.6的wsimport命令报同样的错误:

D:\temp>c:wsimport -s . -d . -p my http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl


引用

[WARNING] src-resolve.4.2: Error resolving component 's:schema'. It was detected that 's:schema' is in namespace 'http:/
/www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'http://webse
rvice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl#types?schema1'. If this is the incorrect namespace, perhaps the pref
ix of 's:schema' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added
to 'http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl#types?schema1'.
  line 15 of http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl#types?schema1

[ERROR] undefined element declaration 's:schema'
  line 15 of http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

[ERROR] undefined element declaration 's:schema'
  line 61 of http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

[ERROR] undefined element declaration 's:schema'
  line 101 of http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl
0 请登录后投票
   发表时间:2013-06-26  
sswh 写道
JDK1.6的wsimport命令报同样的错误:

D:\temp>c:wsimport -s . -d . -p my http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl


引用

[WARNING] src-resolve.4.2: Error resolving component 's:schema'. It was detected that 's:schema' is in namespace 'http:/
/www.w3.org/2001/XMLSchema', but components from this namespace are not referenceable from schema document 'http://webse
rvice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl#types?schema1'. If this is the incorrect namespace, perhaps the pref
ix of 's:schema' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added
to 'http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl#types?schema1'.
  line 15 of http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl#types?schema1

[ERROR] undefined element declaration 's:schema'
  line 15 of http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

[ERROR] undefined element declaration 's:schema'
  line 61 of http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

[ERROR] undefined element declaration 's:schema'
  line 101 of http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

 

 我还没用过CXF对这个服务进行调用,不确定是不是服务的问题,等我测试了,回复你!!

0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics