将Axis XML响应作为Object或String获取

时间:2018-06-11 18:24:25

标签: java client axis

我已经使用AXIS创建了一个客户端,我必须使用WebService。我发送XML作为参数的值。我应该得到相同的响应,另一个名为cadenaXml的参数,值应该是格式化为String或Object的XML,以便我可以将其解组为Java对象。我的代码如下所示:

    String url = "http://localhost:9001/pedido";
    String stringXml = "<hi>Hello</hi>";

    //Create a WebService Call
    Service service = new Service();
    Call call = (Call) service.createCall();                    
    call.setTargetEndpointAddress(new URL(url));

    call.addParameter("cadenaXml", 
              org.apache.axis.Constants.XSD_STRING,
              javax.xml.rpc.ParameterMode.IN);
    call.setUseSOAPAction(true);
    call.setSOAPActionURI("");
    call.setEncodingStyle(null);
    call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
    call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
    call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
    call.setOperationName(new javax.xml.namespace.QName("http://wsaa.view.sua.dvadac.desein.afip.gov", "q1:procesarWS"));

    Object resp = call.invoke(new java.lang.Object[]{stringXml});

如果我执行该代码,我收到以下错误:

org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
    at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
    at org.apache.axis.client.Call.invoke(Call.java:2470)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at toyota.dsa.client.main.Main.function8(Main.java:164)
    at toyota.dsa.client.main.Main.main(Main.java:42)

问题在于,由于XML格式,OUT参数的值被解释为子对象。我需要将此XML读取为String值。

我对这个回答的嘲笑就是这个:

<cadenaXml xsi:type="xsd:string"><pedido><moduloRioserv>001</moduloRioserv><codproducto>001</codproducto><instancia>01</instancia><funcion>6</funcion><cuit>30500750215</cuit><marEmpresa>0</marEmpresa><tpoRendicion>RND</tpoRendicion><fechaDesde>20130422</fechaDesde><fechaHasta>20130422</fechaHasta></pedido></cadenaXml>

提前致谢。

0 个答案:

没有答案