WebService 客戶端實現報錯
用java實現WebService客戶端的時候,獲取自定義返回值時,報錯:
嚴重: No returnType was specified to the Call object! You must call setReturnType() if you have called addParameter().
五月 14, 2018 2:59:31 下午 org.apache.axis.client.Call invoke
嚴重: Exception:
org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.
at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(SimpleDeserializer.java:145)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)
at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
at org.apache.axis.client.Call.invoke(Call.java:2467)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.WebServiceClient.doService(WebServiceClient.java:45)
at com.WebServiceClient.main(WebServiceClient.java:52)
這是因為沒有給設定序列化操作,導致沒有識別自定義類;
在遠端訪問介面前,設定:GetInfoResult是自定義的實體類
call.registerTypeMapping(
GetInfoResult.class,
new QName(namespace,"GetInfoResult"),
new BeanSerializerFactory(GetInfoResult.class, new QName(namespace, "GetInfoResult")),
new BeanDeserializerFactory(GetInfoResult.class, new QName(namespace, "GetInfoResult")));