JAX-WS:独立于 WSDL 的编译模式
如果有多个 Web 服务中使用的相当大的模式,因此我想将 XSD 编译与 WSDL 编译分开。在一个简化的示例中,在单个步骤中编译的工作原理是:
$ wsimport -verbose service.wsdl
parsing WSDL...
Generating code...
org/example/wsdl/mysvc/MySvcPortType.java
org/example/wsdl/mysvc/MySvcService.java
org/example/ns1/Element1.java
org/example/ns1/ObjectFactory.java
org/example/ns1/package-info.java
...
编译 xsd 并使用生成的剧集文件不起作用:
$ wsimport -b schema3.episode service.wsdl
parsing WSDL...
[ERROR] Schema descriptor {http://www.example.org/ns1}element1 in
message part "part1" is not defined and could not be bound to Java.
Perhaps the schema descriptor {http://www.example.org/ns1}element1 is
not defined in the schema imported/included in the WSDL. You can
either add such imports/includes or run wsimport and provide the
schema location using -b switch. line 9 of
file:...jaxepisode_element/service.wsdl
那么如何在wsimport中使用预编译的模式呢?
附录:当包含在另一个模式中时使用该情节可以工作并避免新的编译(d3.jar包含来自schema3 + schema3.episode的genrated类作为META-INF / sun-jaxb.episode):
$ xjc schema4.xsd d3.jar -extension
parsing a schema...
compiling a schema...
org/example/ns2/Element2.java
org/example/ns2/ObjectFactory.java
org/example/ns2/package-info.java
没有预编译的包:
$ xjc schema4.xsd -extension
parsing a schema...
compiling a schema...
org/example/ns1/Element1.java
org/example/ns1/ObjectFactory.java
org/example/ns1/package-info.java
org/example/ns2/Element2.java
org/example/ns2/ObjectFactory.java
org/example/ns2/package-info.java
WSDL:
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://example.org/wsdl/MySvc" xmlns:ns="http://www.example.org/ns1" targetNamespace="http://example.org/wsdl/MySvc" name="MySvc">
<types>
<xsd:schema>
<xsd:import namespace="http://www.example.org/ns1" schemaLocation="schema3.xsd"/>
</xsd:schema>
</types>
<message name="myOpRequest">
<part name="part1" element="ns:element1"/>
</message>
<message name="myOpReply">
<part name="part1" element="ns:element1"/>
</message>
<portType name="MySvcPortType">
<operation name="myOp">
<input name="input1" message="tns:myOpRequest"/>
<output name="output1" message="tns:myOpReply"/>
</operation>
</portType>
<binding name="MySvcBinding" type="tns:MySvcPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="myOp">
<soap:operation/>
<input name="input1">
<soap:body use="literal"/>
</input>
<output name="output1">
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="MySvcService">
<port name="MySvcPort" binding="tns:MySvcBinding">
<soap:address location="http://localhost:8080/"/>
</port>
</service>
</definitions>
schema3.xsd:
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/ns1"
xmlns:tns="http://www.example.org/ns1"
elementFormDefault="qualified">
<element name="element1" >
<complexType >
<sequence>
<element name="name" type="string" />
</sequence>
</complexType>
</element>
</schema>
schema4.xsd:
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/ns2"
xmlns:tns="http://www.example.org/ns2"
xmlns:ns1="http://www.example.org/ns1"
elementFormDefault="qualified">
<import namespace="http://www.example.org/ns1" schemaLocation="schema3.xsd"/>
<element name="element2" >
<complexType >
<sequence>
<element ref="ns1:element1" />
</sequence>
</complexType>
</element>
</schema>
生成的剧集文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<bindings version="2.1" xmlns="http://java.sun.com/xml/ns/jaxb">
<bindings scd="x-schema::tns" xmlns:tns="http://www.example.org/ns1">
<schemaBindings map="false">
<package name="org.example.ns1"/>
</schemaBindings>
<bindings scd="tns:element1">
<class ref="org.example.ns1.Element1"/>
</bindings>
</bindings>
</bindings>