2

我正在开发基于 Spring-WS 的合同优先 Web 服务。我依赖于 Castor 编组,我遇到了以下问题。

当在 Envelope 标记中定义“xmlns”命名空间时,请求被接受,例如:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
                      xmlns="http://www.mycompany.com/MyService/schemas">
  <soap:Header/>
  <soap:Body>
    <doPlaceHoldRequest>
      <hold>
        <accountInfo>
          <accountNumber>123456789</accountNumber>
        </accountInfo>
        <extended>false</extended>
        <afterHours>false</afterHours>
        <amountSavings>1.00</amountSavings>
        <amountChecking>0.00</amountChecking>
      </hold>
    </doPlaceHoldRequest>
  </soap:Body>
</soap:Envelope>

但是,从 Spring-WS 提供的 .wsdl(从 XSD 生成)生成的 .NET 和 Java 客户端都以下列方式形成它们的请求:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header/>
  <soap:Body>
    <doPlaceHoldRequest 
                xmlns="http://www.mycompany.com/MyService/schemas">
      <hold>
        <accountInfo>
          <accountNumber>123456789</accountNumber>
        </accountInfo>
        <extended>false</extended>
        <afterHours>false</afterHours>
        <amountSavings>1.00</amountSavings>
        <amountChecking>0.00</amountChecking>
      </hold>
    </doPlaceHoldRequest>
  </soap:Body>
</soap:Envelope>

这会导致 Castor 抛出 Unmarshalling Exception。如何让 Castor 将这些消息识别为有效?我的 WSDL(或我用来自动生成它的 XSD)可能是错误的吗?

4

2 回答 2

2

我在使用我的第一个 Spring-WS/Castor Web 服务时一遍又一遍地遇到了这个问题。据我所知,某些组件以非命名空间感知的方式提取有效负载。换句话说,像 doPlaceHoldRequest 这样的节点在不继承顶级命名空间声明的情况下成为 XML 文档的根,在上述两种情况下,导致一个您想要的命名空间中,一个不在您想要的命名空间中 - 所以一个可以针对您的架构进行很好的验证,而另一个则不能。

最好的解决方案似乎是覆盖所有基础。使您的 XSD 具有 elementFormDefault="qualified",以要求您的所有元素都位于命名空间中。然后在 Castor 映射中的每个 map-to 元素中指定一个 ns-uri 和一个 ns-prefix。结果有点重,包含所有的命名空间前缀,但是当涉及到惰性客户端服务器组件中的未记录行为时,它似乎变得不那么脆弱了。

JAX-WS 返回空列表也是一个很好的观点。org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor值得验证进出的内容。

于 2011-02-16T00:56:52.520 回答
1

如果你看到这个博客我认为永远不会去其他网络服务:) http://springkbase.blogspot.com/2009/06/spring-webservice-with-castor.html

于 2009-06-14T05:10:14.793 回答