0

我对 WSDL+XSD 有疑问。通过使用 Apache CXF,我的 WSDL 和 XSD 可以正常工作:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://com.schema.goodsservice"
    xmlns="http://com.schema.goodsservice" 
    xmlns:tr="http://com.schema.goods"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

    <wsdl:types>
        <xsd:schema targetNamespace="http://com.schema.goodsservice">
            <xsd:import namespace="http://com.schema.goods"   schemaLocation="goods.xsd" />
        </xsd:schema>
    </wsdl:types>

    <wsdl:message name="goodsInput">
        <wsdl:part name="goods"   element="tr:goods"  />
    </wsdl:message>

    <wsdl:message name="goodsOutput">
        <wsdl:part name="status"  element="tr:status" />
    </wsdl:message>

    <wsdl:portType name="GoodsService">
        <wsdl:operation name="addgoods">
            <wsdl:input message="goodsInput" />
            <wsdl:output message="goodsOutput" />
        </wsdl:operation>
    </wsdl:portType>

    <wsdl:binding name="GoodsServiceHTTPBinding" type="GoodsService">
        <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
            <wsdl:operation name="addgoods">
                <wsdlsoap:operation soapAction="" />
                    <wsdl:input>
                        <wsdlsoap:body use="literal" />
                    </wsdl:input>
                <wsdl:output>
                    <wsdlsoap:body use="literal" />
                </wsdl:output>
            </wsdl:operation>
    </wsdl:binding>

    <wsdl:service name="GoodsServicePorts">
        <wsdl:port binding="GoodsServiceHTTPBinding" name="GoodsService">
            <wsdlsoap:address
                location="http://localhost:9084/goodsService/GoodsServicePorts" />
            </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

和 XSD:

<?xml version="1.0" encoding="UTF-8"?>

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

    <!-- web service input types -->

    <xsd:element name="goods">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="parent_goods" type="parent_good" minOccurs="1" maxOccurs="unbounded" />
                <xsd:element name="child_goods" type="child_good" minOccurs="1" maxOccurs="unbounded" />
                <xsd:element name="login" type="xsd:string" minOccurs="1" maxOccurs="1" />
                <xsd:element name="password" type="xsd:string" minOccurs="1" maxOccurs="1" />
            </xsd:sequence> 
        </xsd:complexType>
    </xsd:element>

    <xsd:complexType name="parent_good">
        <xsd:sequence>
            <xsd:element name="age_beauty" type="xsd:string" minOccurs="0" maxOccurs="1" />
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="child_good">
        <xsd:sequence>
            <xsd:element name="age" type="xsd:integer" minOccurs="0" maxOccurs="1" />
        </xsd:sequence>
    </xsd:complexType>

    <!-- web service output types -->

    <xsd:element name="status">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="iserror" type="xsd:boolean" minOccurs="1" maxOccurs="1" />
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>

任务是从 XSD 文件中删除 targetNamespace。如果 WSDL 的 targetNamespace 必须与 XSD 相同,我该怎么做?

谢谢!

4

0 回答 0