【问题标题】:JAX-WS return empty listsJAX-WS 返回空列表
【发布时间】:2010-08-30 14:11:12
【问题描述】:

我是网络服务的新手。我遇到了一些问题。 在服务器端,我使用的是 spring-ws。在客户端,我使用的是 jax-ws。 使用 wsimport 工具,我根据我的 wsdl 生成了 java 类。

一切正常,但由于某种原因,jax-ws 无法正确解析数组和列表,所有列表都是空的

我绝对确定,响应格式正确,用soapui测试过,我也在使用日志拦截器来记录输出响应。

下面是响应的sn-ps

响应看起来像

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <firstElementResponse>
         <name>hello world text</name>
         <name>hello world text</name>
         <name>hello world text</name>
      </firstElementResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

和wsdl的sn-ps

<xs:complexType name="sayHelloResponseType">
  <xs:sequence>
    <xs:element maxOccurs="unbounded" minOccurs="0" name="name" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

为了生成客户端代码,我使用 wsimport。

SayHelloResponseType resp = serv.sayHello(r);
List<String> name = resp.getName();
System.out.println(name.size());

谢谢。任何帮助将不胜感激。

【问题讨论】:

    标签: java soap jax-ws spring-ws


    【解决方案1】:

    似乎它只是一个无效的响应体,这不是数学 wsdl shema。 spring-ws 和 jax-ws 都不会抛出异常。它只是将无效数据解析为空列表而没有任何警告。

    org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor 拯救了我的一天

    可能我必须调整 jax-ws 的日志记录以避免下次出现这种情况

    【讨论】:

      【解决方案2】:

      我刚刚在How can I handle Castor unmarshaling of SOAP messages when the namespace is defined inside the operation tag? 中回答了一个类似的问题 - 如果您使用的是 Spring-WS,那么您正在编写合同优先的 Web 服务,因此请确保您确实确定了该合同。将所有元素放在命名空间中,确保 XSD 架构期望元素是合格的,并在 Castor 映射中声明 ns-uri 和 ns-prefixes。这是值得的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-07-30
        • 2012-12-01
        • 2011-11-02
        • 2013-02-26
        • 2012-07-09
        • 1970-01-01
        • 2013-12-04
        相关资源
        最近更新 更多