如何在WSDL文件外部指定JAXB自定义?

Chr*_*ltz 6 wsdl jax-ws jaxb wsimport

我有一个用.NET实现的服务的WSDL文件.我也有相同的文件,由第三方制作的一些"自定义"使文件可以容忍wsimport,主要是形式:

<s:annotation>
  <s:appinfo>
    <jaxb:property name="result"/>
  </s:appinfo>
</s:annotation>
Run Code Online (Sandbox Code Playgroud)

我希望能够处理来自供应商的原始 WSDL以及这些覆盖,但我想在外部指定它们.我看到我可以使用"绑定文件" -b选项wsimport,我试图写一个目前看起来像这样的覆盖文件:

<jxb:bindings version="1.0"
  xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <jxb:bindings node="//xs:element[@name='MyElementResult']">
    <jxb:property name="result"/>
  </jxb:bindings>
</jxb:bindings>
Run Code Online (Sandbox Code Playgroud)

我已经验证了"MyElementName"确实存在,在这里找到的元素中:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
     xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
     xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
     xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
     xmlns:tns="vendor-uri"
     xmlns:s="http://www.w3.org/2001/XMLSchema"
     xmlns:s2="http://microsoft.com/wsdl/types/"
     xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
     xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
     targetNamespace="vendor-namespace"
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">

  [...]
  <s:element name="MyElementResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="MyElementResult" type="tns:Result" />
Run Code Online (Sandbox Code Playgroud)

我收到了这个警告(因此没有变化)wsimport:

[ERROR] XPath evaluation of "//xs:element[@name='MyElementResult']" results in empty target node
  line 4 of file:/Users/..../wsdl/custom-bindings.xjb
Run Code Online (Sandbox Code Playgroud)

我在申报单上遗漏了什么吗?我的XPath表达式不正确吗?如果我的XPath /覆盖工作正常,它是否正确格式化以获得与编辑原始WSDL相同的结果?

这甚至可以使用外部文件,还是我必须使用这些相同的更改重新修改WSDL的任何未来版本?

Mic*_*gar 1

您需要在绑定 XML 文件中给出架构位置。

<jxb:bindings version="1.0"
     xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
     xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jxb:bindings 
         schemaLocation="PATH_TO_YOUR_WSDL#types?schema1"
         node="//xs:schema[@targetNamespace='SCHEMA_NAMESPACE']">
        <jxb:bindings node="//xs:element[@name='MyElementResult']">
            <jxb:property name="result"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>
Run Code Online (Sandbox Code Playgroud)

WSDL 文件名后面的内容#types?schema1将指定您要绑定的 WSDL 中的模式,从 1 开始。