【问题标题】:JAXB support for SOAP style arrayTypeJAXB 对 SOAP 样式 arrayType 的支持
【发布时间】:2015-07-20 11:11:49
【问题描述】:

我正在尝试制作一个新版本的服务器,该服务器以前使用 Axis 1.4 来响应使用 Spring-WS 的 SOAP RPC 请求。我有一些 RPC 调用正在工作,但我一直在尝试满足一个需要如下所示 SOAP 主体的请求:

<rpcCallResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <responseElement soapenc:arrayType="xsd:string[5]" 
        xsi:type="soapenc:Array" 
        xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
      <responseElement xsi:type="xsd:string">val1</responseElement>
      <responseElement xsi:type="xsd:string">val2</responseElement>
      <responseElement xsi:type="xsd:string">val3</responseElement>
      <responseElement xsi:type="xsd:string" xsi:nil="true"/>
      <responseElement xsi:type="xsd:string" xsi:nil="true"/>
   </responseElement>
</rpcCallResponse>

我正在努力为此编写 XML 架构,并让 JAXB 编组器将 xsi:type 注释推入响应中。

正确的 XML 模式是什么?使用什么注释集来正确编组(Java -> XML)?

【问题讨论】:

    标签: java xml web-services soap jaxb


    【解决方案1】:

    我发现添加 arrayType 的一个解决方案是使用以下形式的自定义模式,而不是从 http://schemas.xmlsoap.org/soap/encoding/ 模式派生:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://schemas.xmlsoap.org/soap/encoding/"
        elementFormDefault="qualified">
        <xs:attribute name="arrayType" type="xs:QName" />
    </xs:schema>
    

    ...它将arrayType 属性的类型替换为xs:QName(与实际类型相比,它只是xs:string)。使用 QName 的优势似乎是 JAXB 将采用 QName 的命名空间并在序列化发生时将其推到元素上——这是获取上述工作模式的主要障碍。

    上面的架构现在看起来像:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns:encoding="http://schemas.xmlsoap.org/soap/encoding/"
        targetNamespace="http://foo.com/bar"
        elementFormDefault="qualified">
    
        <xs:import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="soapenc.xsd" />
    
        <xs:element name="rpcCallResponse">
            <xs:complexType>
                <xs:element name="responseElement">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="responseElement" maxOccurs="5" />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:attribute ref="soapenc:arrayType" />
            </xs:complexType>
        </xs:element>
    </xs:schema>
    

    【讨论】:

      猜你喜欢
      • 2012-08-09
      • 2020-10-31
      • 2011-07-22
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多