java - 如何解决SAXException : Invalid element in

标签 java web-services wsdl axis sax

我尝试通过以下方式从网络服务获取结果。

List result = new Vector();
LibrarySearchRequest request = new LibrarySearchRequest(queryString);
LibrarySearchServicePortTypeProxy proxy = 
                                new LibrarySearchServicePortTypeProxy();
LibrarySearchServicePortType port = proxy.getLibrarySearchServicePortType();
LibrarySearchResponse response = port.process(request);
librarysearch.soft.Book[] books = response.getBooks();

当我这样做时,我得到以下异常(堆栈跟踪):

org.xml.sax.SAXException: Invalid element in librarysearch.soft.Book - book
at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeserializer.java:258)
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 librarysearch.soft.LibrarySearchServiceSOAP11BindingStub.process(LibrarySearchServiceSOAP11BindingStub.java:180)
at softarch.portal.db.ws.WS_RegularDatabase.findRecords(WS_RegularDatabase.java:44)
at softarch.portal.db.test.TestWSRegularDatabase.main(TestWSRegularDatabase.java:39)

The regular database has caught an unexpected exception: ; nested exception is: 
org.xml.sax.SAXException: Invalid element in librarysearch.soft.Book - book

我读到问题可能是由于 web 服务返回的结果与从 wsdl 生成的类不匹配引起的。我重新生成了我的网络服务客户端,但没有成功。还有什么问题?

最佳答案

这可能与 Axis 1.x Unresolved 错误 ( AXIS-2758) 有关。

如果您的客户端 stub 与服务器端(WSDL 文件)不是最新的,就会出现此问题。您可能必须重新生成它。 喜欢 axistools:wsdl2java .

如果您至少使用 Java 6,现在最好的可能是在客户端使用 JAX-WS (JAX-WS Maven Plugin)。但它无法与使用 RPC/Encoded 的旧 SOAP 服务一起使用...更喜欢文档/文字样式。

关于java - 如何解决SAXException : Invalid element in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16090243/

相关文章:

mysql - 如何使用node.js创建一个webservice来将数据插入mysql?

java - 从 WSDL 生成 java 文件 - 测试与生产 WSDL

java - 在 Tomcat 中设置 Hibernate session 工厂

java - 是否支持 log4j.properties 文件包含?

java - 如何实现新版本的Web服务

javascript - window.open 和 .Net Web 服务

python - 是否可以缓存 python suds 客户端?

c# - WSDL 排序顺序是否相关?

java - JUnit 消息是否应该说明成功或失败的条件?

java - 如何在 Spring 中将值连接到字段?