java webservice wsimport 无法将名称 'soapenc:Array' 解析为 'type definition' 组件 时对应的解决方法
(一):代码如下:
package com.enso.uploaddata; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.junit.Test; import javax.xml.namespace.QName; import javax.xml.rpc.ParameterMode; import javax.xml.rpc.encoding.XMLType; /** * nanjin enso projects * * @author: Mr. Wang * @create: 2018-06-2018/6/1 * @description: */ public class testWebService { @Test public void testWebService () throws Exception{ String url = "http://106.37.208.228:8083/ForecastService.asmx?WSDL" ; //创建客户端调用webservice的代理对象 Service service = new Service(); try { //创建一个调用对象,代表对web service 的一次调用 Call call = (Call) service.createCall(); //设置web service的url 地址 call.setTargetEndpointAddress(new java.net.URL(url)); //设置操作名称,QName 对象的两个参数分别为命名空间和方法名称 call.setOperationName(new QName("http://tempuri.org/","UploadProvinceData")); //不加这行会抛异常System.Web.Services.Protocols.SoapException: 服务器未能识别 HTTP 头 SOAPAction 的值: call.setSOAPActionURI("http://tempuri.org/UploadProvinceData"); //传参 call.addParameter(new QName("http://tempuri.org/", "loginName"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "password"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "forecastInfo"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "warningInfo"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "healthTip"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "moreInfo"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "moreInfoGraphName"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "moreInfoGraphBytes"), XMLType.XSD_BASE64, ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "isFormGraph"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "formOrSceneryGraphName"), XMLType.XSD_STRING, ParameterMode.IN); call.addParameter(new QName("http://tempuri.org/", "formOrSceneryGraphBytes"), XMLType.XSD_BASE64, ParameterMode.IN); //设置返回值类型 call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); // 执行调用操作,result 保存返回的结果,invoke 的参数为实参 String result = (String) call.invoke(new Object[]{"loginName","password","forecastInfo","warningInfo","healthTip","moreInfo","",new byte[1],"false","",new byte[1]}); System.out.println(result); }catch (Exception e){ e.printStackTrace(); } } }
(二) 或者:ws增加schemaLocation(<s:import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/> )。如下:
<s:schema targetNamespace="http://iamsweb.gmcc.net/WS/AbstractTypes"> <s:import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/> <s:complexType name="StringArray"> <s:complexContent mixed="false"> <s:restriction base="soapenc:Array"> <s:sequence> <s:element minOccurs="0" maxOccurs="unbounded" name="String" type="s:string" /> </s:sequence> </s:restriction> </s:complexContent> </s:complexType> </s:schema>