将 xsd 导入 wsdl [英] Importing xsd into wsdl

查看:52
本文介绍了将 xsd 导入 wsdl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我当前的配置:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://stock.com/schemas/services/stock"
    xmlns:tns="http://stock.com/schemas/services/stock"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  elementFormDefault="qualified"  targetNamespace="http://stock.com/schemas/services/stock">

<xsd:element name="Stock">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="ticker" nillable="true" type="xsd:string"/>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="quotes" nillable="true" type="Quote"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

<xsd:complexType name="Quote">
    ........
</xsd:complexType>
.......
<xsd:element name="gethighBetaStockResponse">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="stock" ref="Stock" minOccurs="1" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

WSDL

<?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>

但是,当 ref="Stock" 更改为 type="Stock" 时,wsdl2java 开始给出输入 {http://stock.com/schemas/services/stock}Stock 被引用但未定义.

However,the moment ref="Stock" is changed to type="Stock",the wsdl2java starts giving Type {http://stock.com/schemas/services/stock}Stock is referenced but not defined.

不知何故,wsdl 和 xsd 导入之间似乎存在冲突 - 但我无法解决它.感谢帮助.

Somehow it seems a clash between wsdl and xsd imports - but I just cant resolve it.Help is appreciated.

推荐答案

这里有几个问题.

首先,XSD 存在一个问题,即元素既被命名又被引用;在你的情况下应该被引用.

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

变化:

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

致:

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

还有:

  • 去掉全局元素Stock
  • 的声明
  • 为名为 Stock
  • 的类型创建复杂类型声明
  • Remove the declaration of the global element Stock
  • Create a complex type declaration for a type named Stock

所以:

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

致:

<xsd:complexType name="Stock">

确保您修复了 xml 结束标记.

Make sure you fix the xml closing tags.

第二个问题是引用外部 XSD 的正确方法是在 wsdl:types 元素中使用带有导入/包含的 XSD 模式.wsdl:import 保留用于引用其他 WSDL 文件.更多信息可通过 WS-I 规范,部分 WSDL 和模式导入.根据 WS-I,您的情况是:

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:

不正确:(你展示的方式)

<?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>

正确:

<?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>

某些 处理器可能支持这两种语法.您发布的 XSD 显示存在问题,请确保首先验证 XSD.

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

如果您在 WSDL 创作方面采用 WS-I 方式会更好.

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

其他问题可能与在定位外部内容时使用相对 URI 和绝对 URI 相关.

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

这篇关于将 xsd 导入 wsdl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆