Importing xsd into wsdl

前端 未结 2 934
一向
一向 2020-12-25 11:32

This is my current configuration:

XSD




        
相关标签:
2条回答
  • 2020-12-25 11:55

    You have a couple of problems here.

    First, the XSD has an issue where an element is both named or referenced; in your case should be referenced.

    Change:

    <xsd:element name="stock" ref="Stock" minOccurs="1" maxOccurs="unbounded"/> 
    

    To:

    <xsd:element name="stock" type="Stock" minOccurs="1" maxOccurs="unbounded"/> 
    

    And:

    • Remove the declaration of the global element Stock
    • Create a complex type declaration for a type named Stock

    So:

    <xsd:element name="Stock">
        <xsd:complexType>
    

    To:

    <xsd:complexType name="Stock">
    

    Make sure you fix the xml closing tags.

    The second problem is that the correct way to reference an external XSD is to use XSD schema with import/include within a wsdl:types element. wsdl:import is reserved to referencing other WSDL files. More information is available by going through the WS-I specification, section WSDL and Schema Import. Based on WS-I, your case would be:

    INCORRECT: (the way you showed it)

    <?xml version="1.0" encoding="UTF-8"?>
    <definitions targetNamespace="http://stock.com/schemas/services/stock/wsdl"
        .....xmlns:external="http://stock.com/schemas/services/stock"
        <import namespace="http://stock.com/schemas/services/stock" location="Stock.xsd" />
        <message name="getStockQuoteResp">
            <part name="parameters" element="external:getStockQuoteResponse" />
        </message>
    </definitions>
    

    CORRECT:

    <?xml version="1.0" encoding="UTF-8"?>
    <definitions targetNamespace="http://stock.com/schemas/services/stock/wsdl"
        .....xmlns:external="http://stock.com/schemas/services/stock"
        <types>
            <schema xmlns="http://www.w3.org/2001/XMLSchema">
                <import namespace="http://stock.com/schemas/services/stock" schemaLocation="Stock.xsd" />             
            </schema>
        </types>
        <message name="getStockQuoteResp">
            <part name="parameters" element="external:getStockQuoteResponse" />
        </message>
    </definitions>
    

    SOME processors may support both syntaxes. The XSD you put out shows issues, make sure you first validate the XSD.

    It would be better if you go the WS-I way when it comes to WSDL authoring.

    Other issues may be related to the use of relative vs. absolute URIs in locating external content.

    0 讨论(0)
  • 2020-12-25 11:57

    import vs. include

    The primary purpose of an import is to import a namespace. A more common use of the XSD import statement is to import a namespace which appears in another file. You might be gathering the namespace information from the file, but don't forget that it's the namespace that you're importing, not the file (don't confuse an import statement with an include statement).

    Another area of confusion is how to specify the location or path of the included .xsd file: An XSD import statement has an optional attribute named schemaLocation but it is not necessary if the namespace of the import statement is at the same location (in the same file) as the import statement itself.

    When you do chose to use an external .xsd file for your WSDL, the schemaLocation attribute becomes necessary. Be very sure that the namespace you use in the import statement is the same as the targetNamespace of the schema you are importing. That is, all 3 occurrences must be identical:

    WSDL:

    xs:import namespace="urn:listing3" schemaLocation="listing3.xsd"/>
    

    XSD:

    <xsd:schema targetNamespace="urn:listing3"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
    

    Another approach to letting know the WSDL about the XSD is through Maven's pom.xml:

    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>xmlbeans-maven-plugin</artifactId>
      <executions>
        <execution>
          <id>generate-sources-xmlbeans</id>
          <phase>generate-sources</phase>
          <goals>
        <goal>xmlbeans</goal>
          </goals>
        </execution>
      </executions>
      <version>2.3.3</version>
      <inherited>true</inherited>
      <configuration>
        <schemaDirectory>${basedir}/src/main/xsd</schemaDirectory>
      </configuration>
    </plugin>
    

    You can read more on this in this great IBM article. It has typos such as xsd:import instead of xs:import but otherwise it's fine.

    0 讨论(0)
提交回复
热议问题