【问题标题】:How to customize the schema inlined inside an imported WSDL如何自定义在导入的 WSDL 中内联的模式
【发布时间】:2011-09-26 00:17:33
【问题描述】:

我有 a.wsdl 和 b.wsdl,其中 a.wsdl 导入 b.wsdl。 现在我必须使用 wsimport 和 JAXB 自定义 b.wsdl 中的模式。但使用 below 自定义会产生错误,即 “对 "wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='b']" 的 XPath 评估会导致目标节点为空

在使用 wsimport 生成客户端代码时,我无法找到在导入的 b.wsdl 中自定义内联架构的方法。

    <jaxws:bindings node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='b']"
               xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
               xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
               xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                   <jaxb:globalBindings>
                    <jaxb:javaType name="java.util.Calendar" xmlType="xsd:dateTime" 
                    parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" 
                    printMethod="javax.xml.bind.DatatypeConverter.printDateTime" />
               </jaxb:globalBindings>
   </jaxws:bindings>

A.wsdl

<definitions targetNamespace="a"
 xmlns="http://schemas.xmlsoap.org/wsdl/"
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:interface="b">
 <import location="b.wsdl" namespace="b"/>
  <service name="Service">
   <port binding="interface:Binding" name="Port">
      <soap:address location="https://localhost/sdk/vpxdService" />
   </port>
  </service>
</definitions>

B.wsdl

<definitions targetNamespace="b"
 xmlns="http://schemas.xmlsoap.org/wsdl/"
 xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
 xmlns:b="b"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <types>
   <schema
     targetNamespace="b"
     xmlns="http://www.w3.org/2001/XMLSchema"
     xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
     xmlns:b="b"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     elementFormDefault="qualified">
     <complexType name="XYZ">
        <sequence>
           <element name="dynamicType" type="xsd:string" minOccurs="0" />
           <element name="val" type="xsd:anyType" maxOccurs="unbounded" />
        </sequence>
     </complexType>
  </types>
 </schema>
</definitions>

【问题讨论】:

    标签: xpath jaxb jax-ws wsimport


    【解决方案1】:

    您是否尝试将以下属性添加到 &lt;jaxws:bindings&gt; 元素?

     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    

     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    

    您在 xpath 表达式中引用 xsd 和 wsdl 命名空间,但在为它们定义 URI 之前,它们不会与目标文档中的 URI 匹配。

    【讨论】:

    • 仅供参考,除了 XML 和 XPATH,我对您使用的技术一无所知,但我没有看到 XPATH 中的命名空间前缀和架构的 URI 之间有任何联系在目标 XML 中使用,这对我来说是一个危险信号。
    • 我已经通过编辑问题添加了命名空间前缀,这也不起作用。除了 jaxws,我没有使用任何其他技术。在这里,我尝试自定义生成的代码以使用 GregorianCalendar 而不是 XMLGregorianCalendar。我在导入的模式上使用了相同的方法,它可以工作,但是当涉及到导入的 WSDL(b.wsdl) 中的内联模式时,它不起作用:-(
    【解决方案2】:

    浏览给定网站后,我修改了外部绑定文件以使用 wsdlLocation="b.wsdl" 而不是 node="wsdl:definitions/wsdl:types/xsd:schema[ @targetNamespace='b']" 做了魔法

    这将确保在 WSDL 中定义的内联模式将根据需要进行自定义。

    <bindings 
     xmlns="http://java.sun.com/xml/ns/jaxb"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl"
     version="2.0">    
      <bindings wsdlLocation="b.wsdl">
        <globalBindings>
          <javaType name="java.util.Calendar" xmlType="xsd:dateTime"
            parseMethod="javax.xml.bind.DatatypeConverter.parseDate"
            printMethod="javax.xml.bind.DatatypeConverter.printDate"
          />
         </globalBindings>  
      </bindings>
    </bindings>
    

    http://fusesource.com/docs/framework/2.1/jaxws/JAXWSCustomTypeMappingOverview.html

    【讨论】:

    • 我对此表示怀疑,但是当没有其他方法可以时,这对我来说非常有效。不过,我使用了&lt;serializable uid="1" /&gt; 而不是&lt;javaType&gt; 位。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多