org.apache.axis2.databinding.ADBException: Unexpected subelement arg0 的解决方法

axis调用webservice如果报错信息为: org.apache.axis2.databinding.ADBException: Unexpected subelement arg0 ,只需加入call.setOperation(_operations[1]);问题就解决了。


package com.zte.eas.ws.pop;

import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

public class Test2  {
    static org.apache.axis.description.OperationDesc [] _operations;

    static {
        _operations = new org.apache.axis.description.OperationDesc[2];
        _initOperationDesc1();
    }

    private static void _initOperationDesc1(){
        org.apache.axis.description.OperationDesc oper;
        org.apache.axis.description.ParameterDesc param;
        oper = new org.apache.axis.description.OperationDesc();
        oper.setName("另外一个无关的调用方法");
        param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("http://xxx.com", "args0"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, false, false);
        param.setOmittable(true);
        param.setNillable(true);
        oper.addParameter(param);
        oper.setReturnType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
        oper.setReturnClass(java.lang.String.class);
        oper.setReturnQName(new javax.xml.namespace.QName("http://xxxx.com", "return"));
        oper.setStyle(org.apache.axis.constants.Style.WRAPPED);
        oper.setUse(org.apache.axis.constants.Use.LITERAL);
        _operations[0] = oper;

        oper = new org.apache.axis.description.OperationDesc();
        oper.setName("你的调用方法");
        param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("http://xxx.xx.xxx.xxx.com", "args0"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, false, false);
        param.setOmittable(true);
        param.setNillable(true);
        oper.addParameter(param);
        oper.setReturnType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
        oper.setReturnClass(java.lang.String.class);
        oper.setReturnQName(new javax.xml.namespace.QName("http://xxx.com", "return"));
        oper.setStyle(org.apache.axis.constants.Style.WRAPPED);
        oper.setUse(org.apache.axis.constants.Use.LITERAL);
        _operations[1] = oper;

    }

	public static void main(String[] args) throws Exception {
		String endpoint = "http://111.111.111.111/ttt/sss?wsdl";
		String namespace = "http://xxx.com"; // namespace
		Service service = new Service();
		Call call = (Call) service.createCall();
		call.setTargetEndpointAddress(new URL(endpoint));
		call.setOperationName(new QName(namespace, "你的调用方法名称")); // 要调用接口方法吗
//		call.setOperation(_operations[1]);
		// call.addParameter("arg0", XMLType.XSD_STRING, ParameterMode.IN);
		// //arg0单表 传入参数
		// call.setReturnClass(String.class);
		String s = "{" + "    \"xxx\":\"MGJ\", "
				+ "   \"fff\":\"test\","
				+ "  \"ddd\":\"test\","
				+ "	\"sss\":\"test\","
				+ "   \"aaa\":\"test\"" + "	}";
		String res = (String) call.invoke(new Object[] { s }); // 调用返回参数
		System.out.println(res);
		// JSONArray jsonArray = new JSONArray(res); //解析json
		// int iSize = jsonArray.length();
		// for (int i = 0; i < iSize; i++) {
		// JSONObject jsonObj = jsonArray.getJSONObject(i);
		// System.out.println("[" + i + "]name=" + jsonObj.get("name"));
		// System.out.println("[" + i + "]id=" + jsonObj.get("id"));
		//
		// //json包含了一个对象,获取对象下的属性
		// JSONObject myjObject2 = jsonObj.getJSONObject("persion");
		// System.out.println("["+i+"]persion id"+myjObject2.getString("id")+"\n");
		// System.out.println("["+i+"]persion username"+myjObject2.getString("username"));
		// System.out.println("["+i+"]persion age"+myjObject2.getString("age"));
		// }
	}
}


你可能感兴趣的:(org.apache.axis2.databinding.ADBException: Unexpected subelement arg0 的解决方法)