- 浏览: 334766 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
zqb666kkk:
有示例代码吗
WebService CXF学习(高级篇3):WS-Security -
zhujiangtaobl0505:
楼主有源码没?发下,我邮箱465971531@qq.com,我 ...
WebService CXF学习(高级篇2):CXF+Spring+Hibernate -
ssy341:
http://localhost:8080/jforum/in ...
JForum安装详解 -
songzht:
看了上面的代码,这两个类型是怎么定义的?private Bas ...
JfreeChar结合struts2展示柱状图和饼状图(已解决乱码问题) -
Getwaysun:
持久化类中使用boolean定义某个字段后,报Null val ...
null不能赋值给int类型,Integer可以。
近期项目中需要用到webservice,接口提供方使用.net编写,返回的是自定义对象,对象中有图片。
接口描述文件如下
wsdl文件如下
调用过程
我在调用接口过程中碰到的难题是对返回对象的接受,返回对象是.net中定义的,在java中接受就需要进行序列化,序列化的问题搞了好几天没进展,最后实在没招了就还是使用啦
AXIS1.4的 wsdl2java 生成客户端,从生成的代码中找到了序列化返回对象的类,修改后直接引用。
返回对象在java中的定义(通过wsdl2java生成)
当时问什么不直接用wsdl2java生成客户端是因为生成的代码在当时还读不懂,没有可控性
所以选择了自己手写客户端,第一次学习使用webservice,有不足地方请大家指正,共同学习,共同前进。
接口描述文件如下
POST /FJJTMapService/Service.asmx HTTP/1.1 Host: 192.168.5.92 Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <ChartService xmlns="http://www.fzis.com.cn/"> <type>string</type> <width>int</width> <height>int</height> <imageType>string</imageType> <fieldnames>string</fieldnames> <fieldvalues>string</fieldvalues> <rgbcolors>string</rgbcolors> <chartType>string</chartType> <size>string</size> </ChartService> </soap12:Body> </soap12:Envelope> HTTP/1.1 200 OK Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> <soap12:Body> <ChartServiceResponse xmlns="http://www.fzis.com.cn/"> <ChartServiceResult> <Xmax>double</Xmax> <Xmin>double</Xmin> <Ymax>double</Ymax> <Ymin>double</Ymin> <MapByte>base64Binary</MapByte> <ErrorMessage>string</ErrorMessage> </ChartServiceResult> </ChartServiceResponse> </soap12:Body> </soap12:Envelope>
wsdl文件如下
//返回对象 <s:complexType name="Map"> - <s:sequence> <s:element minOccurs="1" maxOccurs="1" name="Xmax" type="s:double" /> <s:element minOccurs="1" maxOccurs="1" name="Xmin" type="s:double" /> <s:element minOccurs="1" maxOccurs="1" name="Ymax" type="s:double" /> <s:element minOccurs="1" maxOccurs="1" name="Ymin" type="s:double" /> <s:element minOccurs="0" maxOccurs="1" name="MapByte" type="s:base64Binary" /> <s:element minOccurs="0" maxOccurs="1" name="ErrorMessage" type="s:string" /> </s:sequence> </s:complexType> //调用方法 - <s:element name="ChartService"> - <s:complexType> - <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="type" type="s:string" /> <s:element minOccurs="1" maxOccurs="1" name="width" type="s:int" /> <s:element minOccurs="1" maxOccurs="1" name="height" type="s:int" /> <s:element minOccurs="0" maxOccurs="1" name="imageType" type="s:string" /> <s:element minOccurs="0" maxOccurs="1" name="fieldnames" type="s:string" /> <s:element minOccurs="0" maxOccurs="1" name="fieldvalues" type="s:string" /> <s:element minOccurs="0" maxOccurs="1" name="rgbcolors" type="s:string" /> <s:element minOccurs="0" maxOccurs="1" name="chartType" type="s:string" /> <s:element minOccurs="0" maxOccurs="1" name="size" type="s:string" /> </s:sequence> </s:complexType> </s:element> - <s:element name="ChartServiceResponse"> - <s:complexType> - <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="ChartServiceResult" type="tns:Map" /> </s:sequence> </s:complexType> </s:element>
调用过程
try { // WebService URL String url = "http://192.168.5.92/FJJTMapService/Service.asmx"; String namespace = "http://www.fzis.com.cn/"; String method = "ChartService"; //创建调用服务 Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new java.net.URL(url)); call.setUseSOAPAction(true); call.setSOAPActionURI(namespace+method); //注册对象 QName qn=new QName(namespace, "Map"); call.registerTypeMapping(RouteThemeResult.class, qn, new org.apache.axis.encoding.ser. BeanSerializerFactory(RouteThemeResult.class, qn), new org.apache.axis.encoding.ser. BeanDeserializerFactory(RouteThemeResult.class, qn)); // 设置要调用的方法 call.setOperationName(new QName(namespace, method)); // 该方法需要的参数 call.addParameter(new QName(namespace,"type"),XMLType.XSD_STRING,ParameterMode.IN); call.addParameter(new QName(namespace,"width"),XMLType.XSD_INT,ParameterMode.IN); call.addParameter(new QName(namespace,"height"),XMLType.XSD_INT,ParameterMode.IN); call.addParameter(new QName(namespace,"imageType"),XMLType.XSD_STRING,ParameterMode.IN); call.addParameter(new QName(namespace,"fieldnames"),XMLType.XSD_STRING,ParameterMode.IN); call.addParameter(new QName(namespace,"fieldvalues"),XMLType.XSD_STRING,ParameterMode.IN); call.addParameter(new QName(namespace,"rgbcolors"),XMLType.XSD_STRING,ParameterMode.IN); call.addParameter(new QName(namespace,"chartType"),XMLType.XSD_STRING,ParameterMode.IN); call.addParameter(new QName(namespace,"size"),XMLType.XSD_STRING,ParameterMode.IN); // 方法的返回值类型 //call.setReturnType(XMLType.XSD_STRING); call.setReturnType(qn); //设置参数 String type = gisChartInfo.getLayername(); int width = gisChartInfo.getWidth(); int height = gisChartInfo.getHeight(); String imageType = gisChartInfo.getImageType(); String fieldnames = gisChartInfo.getFieldnames(); String fieldvalues = gisChartInfo.getFieldvalues(); String rgbcolors = gisChartInfo.getRgbcolors(); String chartType = gisChartInfo.getChartType(); String size = gisChartInfo.getSize(); Object[] parameters = null; parameters = new Object[]{type,width+"",height+"",imageType,fieldnames,fieldvalues,rgbcolors,chartType,size}; // 调用该方法 byte[] imageBytes ; RouteThemeResult result = new RouteThemeResult() ; Object obj = call.invoke(parameters); if(obj!=null){ System.out.println("ishere:"); if (obj instanceof java.rmi.RemoteException) { throw (java.rmi.RemoteException)obj; } else { try { result = (RouteThemeResult) obj; } catch (java.lang.Exception _exception) { result = (RouteThemeResult) org.apache.axis.utils.JavaUtils.convert(obj, RouteThemeResult.class); } } }
我在调用接口过程中碰到的难题是对返回对象的接受,返回对象是.net中定义的,在java中接受就需要进行序列化,序列化的问题搞了好几天没进展,最后实在没招了就还是使用啦
AXIS1.4的 wsdl2java 生成客户端,从生成的代码中找到了序列化返回对象的类,修改后直接引用。
返回对象在java中的定义(通过wsdl2java生成)
public class RouteThemeResult implements java.io.Serializable { private double xmax; private double xmin; private double ymax; private double ymin; private byte[] mapByte; private java.lang.String errorMessage; public RouteThemeResult() { } public RouteThemeResult( double xmax, double xmin, double ymax, double ymin, byte[] mapByte, java.lang.String errorMessage) { this.xmax = xmax; this.xmin = xmin; this.ymax = ymax; this.ymin = ymin; this.mapByte = mapByte; this.errorMessage = errorMessage; } /** * Gets the xmax value for this Map. * * @return xmax */ public double getXmax() { return xmax; } /** * Sets the xmax value for this Map. * * @param xmax */ public void setXmax(double xmax) { this.xmax = xmax; } /** * Gets the xmin value for this Map. * * @return xmin */ public double getXmin() { return xmin; } /** * Sets the xmin value for this Map. * * @param xmin */ public void setXmin(double xmin) { this.xmin = xmin; } /** * Gets the ymax value for this Map. * * @return ymax */ public double getYmax() { return ymax; } /** * Sets the ymax value for this Map. * * @param ymax */ public void setYmax(double ymax) { this.ymax = ymax; } /** * Gets the ymin value for this Map. * * @return ymin */ public double getYmin() { return ymin; } /** * Sets the ymin value for this Map. * * @param ymin */ public void setYmin(double ymin) { this.ymin = ymin; } /** * Gets the mapByte value for this Map. * * @return mapByte */ public byte[] getMapByte() { return mapByte; } /** * Sets the mapByte value for this Map. * * @param mapByte */ public void setMapByte(byte[] mapByte) { this.mapByte = mapByte; } /** * Gets the errorMessage value for this Map. * * @return errorMessage */ public java.lang.String getErrorMessage() { return errorMessage; } /** * Sets the errorMessage value for this Map. * * @param errorMessage */ public void setErrorMessage(java.lang.String errorMessage) { this.errorMessage = errorMessage; } private java.lang.Object __equalsCalc = null; public synchronized boolean equals(java.lang.Object obj) { if (!(obj instanceof RouteThemeResult)) return false; RouteThemeResult other = (RouteThemeResult) obj; if (obj == null) return false; if (this == obj) return true; if (__equalsCalc != null) { return (__equalsCalc == obj); } __equalsCalc = obj; boolean _equals; _equals = true && this.xmax == other.getXmax() && this.xmin == other.getXmin() && this.ymax == other.getYmax() && this.ymin == other.getYmin() && ((this.mapByte==null && other.getMapByte()==null) || (this.mapByte!=null && java.util.Arrays.equals(this.mapByte, other.getMapByte()))) && ((this.errorMessage==null && other.getErrorMessage()==null) || (this.errorMessage!=null && this.errorMessage.equals(other.getErrorMessage()))); __equalsCalc = null; return _equals; } private boolean __hashCodeCalc = false; public synchronized int hashCode() { if (__hashCodeCalc) { return 0; } __hashCodeCalc = true; int _hashCode = 1; _hashCode += new Double(getXmax()).hashCode(); _hashCode += new Double(getXmin()).hashCode(); _hashCode += new Double(getYmax()).hashCode(); _hashCode += new Double(getYmin()).hashCode(); if (getMapByte() != null) { for (int i=0; i<java.lang.reflect.Array.getLength(getMapByte()); i++) { java.lang.Object obj = java.lang.reflect.Array.get(getMapByte(), i); if (obj != null && !obj.getClass().isArray()) { _hashCode += obj.hashCode(); } } } if (getErrorMessage() != null) { _hashCode += getErrorMessage().hashCode(); } __hashCodeCalc = false; return _hashCode; } // Type metadata private static org.apache.axis.description.TypeDesc typeDesc = new org.apache.axis.description.TypeDesc(RouteThemeResult.class, true); static { typeDesc.setXmlType(new javax.xml.namespace.QName("http://www.fzis.com.cn/", "Map")); org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc(); elemField.setFieldName("xmax"); elemField.setXmlName(new javax.xml.namespace.QName("http://www.fzis.com.cn/", "Xmax")); elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "double")); elemField.setNillable(false); typeDesc.addFieldDesc(elemField); elemField = new org.apache.axis.description.ElementDesc(); elemField.setFieldName("xmin"); elemField.setXmlName(new javax.xml.namespace.QName("http://www.fzis.com.cn/", "Xmin")); elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "double")); elemField.setNillable(false); typeDesc.addFieldDesc(elemField); elemField = new org.apache.axis.description.ElementDesc(); elemField.setFieldName("ymax"); elemField.setXmlName(new javax.xml.namespace.QName("http://www.fzis.com.cn/", "Ymax")); elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "double")); elemField.setNillable(false); typeDesc.addFieldDesc(elemField); elemField = new org.apache.axis.description.ElementDesc(); elemField.setFieldName("ymin"); elemField.setXmlName(new javax.xml.namespace.QName("http://www.fzis.com.cn/", "Ymin")); elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "double")); elemField.setNillable(false); typeDesc.addFieldDesc(elemField); elemField = new org.apache.axis.description.ElementDesc(); elemField.setFieldName("mapByte"); elemField.setXmlName(new javax.xml.namespace.QName("http://www.fzis.com.cn/", "MapByte")); elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "base64Binary")); elemField.setMinOccurs(0); elemField.setNillable(false); typeDesc.addFieldDesc(elemField); elemField = new org.apache.axis.description.ElementDesc(); elemField.setFieldName("errorMessage"); elemField.setXmlName(new javax.xml.namespace.QName("http://www.fzis.com.cn/", "ErrorMessage")); elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string")); elemField.setMinOccurs(0); elemField.setNillable(false); typeDesc.addFieldDesc(elemField); } /** * Return type metadata object */ public static org.apache.axis.description.TypeDesc getTypeDesc() { return typeDesc; } /** * Get Custom Serializer */ public static org.apache.axis.encoding.Serializer getSerializer( java.lang.String mechType, java.lang.Class _javaType, javax.xml.namespace.QName _xmlType) { return new org.apache.axis.encoding.ser.BeanSerializer( _javaType, _xmlType, typeDesc); } /** * Get Custom Deserializer */ public static org.apache.axis.encoding.Deserializer getDeserializer( java.lang.String mechType, java.lang.Class _javaType, javax.xml.namespace.QName _xmlType) { return new org.apache.axis.encoding.ser.BeanDeserializer( _javaType, _xmlType, typeDesc); } }
当时问什么不直接用wsdl2java生成客户端是因为生成的代码在当时还读不懂,没有可控性
所以选择了自己手写客户端,第一次学习使用webservice,有不足地方请大家指正,共同学习,共同前进。
评论
2 楼
lianj_lee
2009-09-10
谢谢 在网上找了N久,没有看到一个像样的文章 都是抄过来抄过去的。
中国的程序员真是相当 “拉及”!
中国的程序员真是相当 “拉及”!
1 楼
lz726
2009-08-11
非常感谢。。。
发表评论
-
svnserver配置文件详解
2013-02-26 15:43 1366svnserve是SVN自带的一个轻型服务器,客户端通过使 ... -
启动tomcat报StandardServer.await: create[8005]
2013-02-19 11:15 1114启动tomcat报StandardServer. ... -
js读取excel
2012-09-26 17:26 2208项目需要用到将excel中的数据导入到页面的文本框中,但并不想 ... -
java里的split函数
2012-04-11 16:55 944今天要用到split函数,对浮点数进行分割为子字符串,然后将结 ... -
sqlserver 2005 Network error IOException: Connection refused: connect
2010-07-12 11:29 1774打开程序 Microsoft SQL Server 服务器网络 ... -
Eclipse快捷键应用
2010-05-18 11:17 11061. 已知接口,查找实现类(已知实现类,查找接口) 光标 ... -
重置mysql5.1的root密码
2009-12-29 15:13 2103首先在 MySQL的安装目录下 新建一个pwdhf.txt, ... -
dom4j生成xml的编码问题
2008-11-11 15:55 1732文章引用:http://blog.csdn.net/redez ... -
null不能赋值给int类型,Integer可以。
2008-03-12 12:00 12485报错Null value was assigned to a ...
相关推荐
本方法是用axis1.4技术,实现java客户端调用webservice。已经可实现过可行的,如果不行可加我QQ号302633进行详细解析。
springboot 集成axis1.4的webservice,该为maven的工程
以前看别人写的,似乎都比较复杂,而且没有提供一个webservice供初学者测试,我找了一个http://www.webservicex.net/globalweather.asmx,根据这个写了一个例子,让新学的少走一些弯路吧
axis1.4开发webservice源码 包含webservice发布 与客户端调用
java axis 调用 .net webservice 短信收发 虽然分要多了些,但是代码注释的很详细,我相信是物有所值的。
用于axis1.4开发webService。 文件包含,axis1.4.ZIP以及其他所需jar包,和生成webservice客户端,生成webService服务端发布 的详细教程说明。
java采用axis调用.net写的WebService,WebService的参数有传人和传出,传出的参数为ref,java端ParameterMode.OUT,传人的为ParameterMode.IN,WebService返回值为String,java利用Map取传出参数,对Map进行遍历取得...
axis2请求.Net webservice接口,以天气预报getSupportCity接口为例
Java使用axis来调用.net写的asmx WebService,大体步骤如下。 Axis需要用到的包如下: 1. axis.jar 2. commons-discovery-0.2.jar 3. commons-logging-1.0.4.jar 4. jaxrpc.jar 5. wsdl4j-1.5.1.jar java调用的代码...
Java调用.NET的WebService接口实例,jar包删减到三个,干净清爽,里面包含注多注释和图解,搞了半天的家伙拿出来与大家分享,无任何BUG,修改里面的参数即可直接运行,对于这种好东西,花了半天时间10分不算高,重在...
axis1.4完整包下载Apache Axis是一种SOAP(简单对象访问协议”)实现。 包含 Axis1.4的所有完整包。
MyEclipse的axis1.4 java的webservice客户端服务端,下载即可直接运动,包括lib
axis1.4生成访问客户端代码
axis1.4生成客户端 根据WSDL生成客户端和服务端
axis1.4和axis2相关jar文件,axis1.4和axis2相关jar文件
使用spring3+ cxf 3.4做服务方,Axis1.4做请求方,在调用的时候,通过转换cxf的wsdl格式为axis1.4的wsdl格式来达到调用的目的。
java org.apache.axis.wsdl.WSDL2Java -u http://xxxxxx?wsdl -p com.webservice.wsdl -t -u 要访问的webservice的地址标准的wsdl文件 -p 生成java文件的包名 -t 生成的java文件中包含junit的测试代码。 详见...
axis1.4+mybatis3+spring3集成实现webservice;websphere下Log4j记录日志解决方案;
说明: 由于上传速度的问题例子面没有加包,请下载后自己将Axis 1.4的lib包放到你的工程里头就可以了。 当然可以调用任何 wsdl地址。只要是webservice 这里是比较流行的。 这里有2个测试地址。 (1)...
基于AXIS1.4实现的webservice客户端和服务端的搭建例子。里面包括完整的服务端demo和客户端demo并附有文档教程