axis2调用 .net的webservice asmx
来源:互联网 发布:关于程序员的电影 编辑:程序博客网 时间:2024/05/16 04:03
源自: http://cqyqing.iteye.com/blog/1668227
1、下载axis2(到apache官网下载www.apache.org)
2、我下载的是axis2-1.5-bin.zip,解压到当前文件夹
3、进入bin目录(F:\study\java\service\axis2\axis2-1.5\bin)
4、打开cmd,进入第3步的bin目录,输入wsdl2java.bat -uri http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl,回车
可能会提示错误,设置一下JAVA_HOME 和 AXIS2_HOME 就好(在WIN的环境变量下面,记得log-off或者重起)
5、之后会在bin目录下生成一个src目录,将src目录下的两个类考到eclipse开发目录下
6、建一个测试类Test,代码如下
import cn.com.webxml.WeatherWebServiceStub; import cn.com.webxml.WeatherWebServiceStub.ArrayOfString; import cn.com.webxml.WeatherWebServiceStub.GetWeatherbyCityName; public class Test { public static void test1(){ try{ WeatherWebServiceStub stub = new WeatherWebServiceStub(); stub._getServiceClient().getOptions().setProperty( org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE); GetWeatherbyCityName city = new GetWeatherbyCityName(); city.setTheCityName("广州"); ArrayOfString array = stub.getWeatherbyCityName(city).getGetWeatherbyCityNameResult(); String[] str = array.getString(); for(String s : str){ System.out.println(s); } }catch(Exception e){ e.printStackTrace(); } } /** * @param args */ public static void main(String[] args) throws Exception{ test1(); } }
原贴的说明,要看一下,有助理解:
需要注意的是这个类GetWeatherbyCityName,这个本来是.net webservice中的一个方法,如下
POST /WebServices/WeatherWebService.asmx HTTP/1.1 Host: www.webxml.com.cn Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://WebXml.com.cn/getWeatherbyCityName" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getWeatherbyCityName xmlns="http://WebXml.com.cn/"> <theCityName>string</theCityName> </getWeatherbyCityName> </soap:Body> </soap:Envelope>
用axis2生成java代码后,会自动生成一个对应的对象,webservice需要传递的参数,可以通过对这个对象赋值操作完成,如上面,我要查广州的天气,就设置为city.setTheCityName("广州");
注意,关键的地方
由于.net webservice中返回的是ArrayOfString,java中没有这个对象,所以axis2会自动生成这个对象,然后转换成对应的数组即可,如String[] str = array.getString();在axis版本中,使用的是返回类型,但是返回类型设置其他的比如String等都会报错,只能设置成VECTOR,即call.setReturnType(XMLType.SOAP_VECTOR),如果只返回一个字符串,可以直接使用STRING;这样才能确保返回正确。
这样一来,很符合我这个没什么时间的懒人,因为有CodeGen。
阅读全文
0 0
- axis2调用 .net的webservice asmx
- axis2通过城市名称调用.net写的asmx WebService查询天气实例
- axis2通过城市名称调用.net写的asmx WebService查询天气实例 .
- ASMX .net Webservice 异步调用
- php 如何利用 soap调用.Net的WebService asmx文件
- .net asmx webservice如何调出测试调用
- axis,axis2调用.net的webservice
- axis,axis2调用.net的webservice
- Java调用Webservice(asmx)的例子
- Java调用Webservice(asmx)的几个例子
- Java调用Webservice(asmx)的几个例子
- Java调用Webservice(asmx)的例子
- Java调用Webservice(asmx)的几个例子
- Java调用Webservice(asmx)的例子
- Java调用Webservice(asmx)的几个例子
- Java调用Webservice(asmx)的例子
- java 调用webservice asmx
- java使用AXIS2调用asp.net的WebService
- 关于spring动态切换数据源
- C/C++结构体总结
- Android AIDL用法介绍
- Pick公式
- c/c++里的 堆区 栈区 静态区 文字常量区 程序代码区
- axis2调用 .net的webservice asmx
- tcp与udp的区别
- JAVA中使用内部类的原因
- java各常用容器总结
- 文件的读取操作(2)
- HTML标签--行级标签
- 搭建git本地服务器
- Qt学习之路(50): QString
- iOS审核被拒合集