【问题标题】:Can't read the SOAP information without the ns2: on the tag. Why?如果标签上没有 ns2:,则无法读取 SOAP 信息。为什么?
【发布时间】:2019-01-08 19:21:52
【问题描述】:

我正在尝试从 SOAP 调用中接收一些信息。我的端点被成功调用,但我的类中的信息是null。只有将<XYZFullDesc/<order_no>更改为<ns2:XYZFullDesc/<ns2:order_no>才能收到信息,但我需要不做任何更改接收XML。

我的 Soap 服务需要接收的整个 XML:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Header/>
   <S:Body>
      <ns2:publishXYZFullModifyUsingXYZFullDesc xmlns:ns2="http://www.oracle.com/retail/igsla/integration/services/XYZFullPublishingService/v1">
         <XYZFullDesc xmlns="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <order_no>2445460</order_no>
         </XYZFullDesc>
       </ns2:publishXYZFullModifyUsingXYZFullDesc>
   </S:Body>
</S:Envelope>

我目前的 XSD 是:

<s:schema xmlns:s="http://www.w3.org/2001/XMLSchema"
           xmlns:tns="http://www.oracle.com/retail/igsla/integration/services/XYZFullPublishingService/v1"
           targetNamespace="http://www.oracle.com/retail/igsla/integration/services/XYZFullPublishingService/v1"
          elementFormDefault="qualified">

    <s:element name="publishXYZFullModifyUsingXYZFullDesc">
        <s:complexType>
            <s:sequence>
                <s:element name="XYZFullDesc" type="tns:XYZFullDesc"/>
            </s:sequence>
        </s:complexType>
    </s:element>

    <s:complexType name="XYZFullDesc">
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="order_no" type="s:string"/>
        </s:sequence>
    </s:complexType>

</s:schema>

我的 Spring 端点:

private static final String NAMESPACE_URI = "http://www.oracle.com/retail/igsla/integration/services/XYZFullPublishingService/v1";

@PayloadRoot(namespace = NAMESPACE_URI, localPart = "publishXYZFullModifyUsingXYZFullDesc")
@ResponsePayload
public void receberPedidoRequest(@RequestPayload PublishXYZFullModifyUsingXYZFullDesc request) {
    // code...
}

那么,ns2 的存在/不存在如何解释这种行为?上面的 XML 怎么读不做任何改动?

【问题讨论】:

    标签: xml spring soap xsd wsdl


    【解决方案1】:

    我最终得到以下解决方案。

    因为我想在同一个架构上有两个命名空间,以便理解阅读主题,import 在我的 XSD 上是必需的。我最初的想法是设置不同的命名空间,但我只能为PublishXYZFullModifyUsingXYZFullDesc 设置一个命名空间,并使用ref 使XYZFullDesc 的命名空间被忽略(不为空,视为无效)。

    主要的 XSD:

    <s:schema xmlns:s="http://www.w3.org/2001/XMLSchema"
               xmlns:po="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1"
               targetNamespace="http://www.oracle.com/retail/abcd/integration/services/XYZFullPublishingService/v1"
              elementFormDefault="qualified">
    
        <s:import schemaLocation="po.xsd"
                   namespace="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1" />
    
        <s:element name="publishXYZFullModifyUsingXYZFullDesc">
            <s:complexType>
                <s:sequence>
                    <s:element ref="po:XYZFullDesc"/>
                </s:sequence>
            </s:complexType>
        </s:element>
    
    </s:schema>
    

    导入的 po.xsd:

    <?xml version="1.0" encoding="utf-16" ?>
    <s:schema targetNamespace="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1"
               xmlns:s="http://www.w3.org/2001/XMLSchema"
               xmlns="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1"
               elementFormDefault="qualified">
    
        <s:element name="XYZFullDesc" type="XYZFullDesc"/>
    
        <s:complexType name="XYZFullDesc">
            <s:sequence>
                <s:element minOccurs="0" maxOccurs="1" name="order_no" type="s:string"/>
            </s:sequence>
        </s:complexType>
    
    </s:schema>
    

    生成的 Java 存根:

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "xyzFullDesc"
    })
    @XmlRootElement(name = "publishXYZFullModifyUsingXYZFullDesc", namespace = "http://www.oracle.com/retail/abcd/integration/services/XYZFullPublishingService/v1")
    public class PublishXYZFullModifyUsingXYZFullDesc {
    
        @XmlElement(name = "XYZFullDesc", required = true) // no namespace, but works for me
        protected XYZFullDesc xyzFullDesc;
    
    }
    

    【讨论】:

      猜你喜欢
      • 2013-11-08
      • 2013-10-20
      • 2011-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-12
      • 1970-01-01
      相关资源
      最近更新 更多