完整的 WSDL 语法

完整的 WSDL 1.1 语法(2025 年生产级最全版)

以下是 WSDL 1.1 所有合法元素的完整结构 + 生产中最常用属性 + 注释说明。直接拿去写任何复杂企业级接口都不会缺标签。

<?xml version="1.0" encoding="UTF-8"?>
<definitions
    name="ServiceName"                                             <!-- 可选,服务名称 -->
    targetNamespace="http://example.com/order/"                    <!-- 必须,你的命名空间 -->
    xmlns="http://schemas.xmlsoap.org/wsdl/"                       <!-- WSDL 默认命名空间 -->
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
    xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
    xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:tns="http://example.com/order/"                          <!-- 通常和 targetNamespace 一样 -->
    xmlns:plt="http://schemas.xmlsoap.org/wsdl/soap/"              <!-- 可选,别名 -->
    >

    <!-- ====================== 1. 导入外部 WSDL / XSD ====================== -->
    <import namespace="http://example.com/common/" location="common-types.wsdl"/>
    <include location="another-part.wsdl"/>   <!-- WSDL 2.0 才支持,1.1 基本不用 -->

    <!-- ====================== 2. 类型系统(types)====================== -->
    <types>
        <xs:schema targetNamespace="http://example.com/order/"
                   elementFormDefault="qualified"
                   attributeFormDefault="unqualified">

            <!-- 导入外部 XSD(强烈推荐,大项目必用) -->
            <xs:import namespace="http://example.com/common/" 
                       schemaLocation="https://c.example.com/common.xsd"/>

            <!-- 简单请求响应 -->
            <xs:element name="CreateOrderRequest">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="customerId" type="xs:string"/>
                        <xs:element name="items" type="tns:OrderItem" minOccurs="0" maxOccurs="unbounded"/>
                        <xs:element name="amount" type="xs:decimal"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

            <xs:element name="CreateOrderResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="orderId" type="xs:string"/>
                        <xs:element name="status" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

            <!-- 复杂类型定义 -->
            <xs:complexType name="OrderItem">
                <xs:sequence>
                    <xs:element name="sku" type="xs:string"/>
                    <xs:element name="qty" type="xs:int"/>
                    <xs:element name="price" type="xs:decimal"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </types>

    <!-- ====================== 3. 消息(message)====================== -->
    <message name="CreateOrderRequestMessage">
        <part name="parameters" element="tns:CreateOrderRequest"/>     <!-- document 风格 -->
        <!-- <part name="header" element="tns:AuthHeader"/> -->        <!-- 可选,Header -->
    </message>
    <message name="CreateOrderResponseMessage">
        <part name="parameters" element="tns:CreateOrderResponse"/>
    </message>

    <!-- 可选:Header 消息 -->
    <message name="AuthHeaderMessage">
        <part name="auth" element="tns:SecurityHeader"/>
    </message>

    <!-- 可选:Fault 消息 -->
    <message name="AuthFaultMessage">
        <part name="fault" element="tns:AuthFault"/>
    </message>

    <!-- ====================== 4. 端口类型(portType)= 接口 ====================== -->
    <portType name="OrderPortType">
        <operation name="CreateOrder">
            <input  message="tns:CreateOrderRequestMessage"/>
            <output message="tns:CreateOrderResponseMessage"/>
            <fault  message="tns:AuthFaultMessage" name="AuthFault"/>
        </operation>
    </portType>

    <!-- ====================== 5. 绑定(binding)====================== -->
    <!-- 5.1 最推荐:SOAP 1.1 document/literal wrapped -->
    <binding name="OrderSoap11Binding" type="tns:OrderPortType">
        <soap:binding style="document" 
                      transport="http://schemas.xmlsoap.org/soap/http"/>

        <operation name="CreateOrder">
            <soap:operation soapAction="http://example.com/order/CreateOrder" 
                            style="document"/>
            <input>
                <!-- <soap:header message="tns:AuthHeaderMessage" part="auth" use="literal"/> -->
                <soap:body use="literal" namespace="http://example.com/order/"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
            <fault name="AuthFault">
                <soap:fault name="AuthFault" use="literal"/>
            </fault>
        </operation>
    </binding>

    <!-- 5.2 SOAP 1.2 版本(推荐新项目) -->
    <binding name="OrderSoap12Binding" type="tns:OrderPortType">
        <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="CreateOrder">
            <soap12:operation soapAction="http://example.com/order/CreateOrder"/>
            <input><soap12:body use="literal"/></input>
            <output><soap12:body use="literal"/></output>
        </operation>
    </binding>

    <!-- 5.3 老式 rpc/encoded(看到就绕道) -->
    <binding name="OrderRpcBinding" type="tns:OrderPortType">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="CreateOrder">
            <soap:operation soapAction=""/>
            <input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
            <output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
        </operation>
    </binding>

    <!-- 5.4 纯 HTTP 绑定(极少用) -->
    <binding name="OrderHttpBinding" type="tns:OrderPortType">
        <http:binding verb="POST"/>
        <operation name="CreateOrder">
            <http:operation location="/CreateOrder"/>
            <input><mime:content type="application/xml"/></input>
            <output><mime:content type="application/xml"/></output>
        </operation>
    </binding>

    <!-- ====================== 6. 服务(service)====================== -->
    <service name="OrderService">
        <!-- 生产环境 -->
        <port name="OrderSoap11Port" binding="tns:OrderSoap11Binding">
            <soap:address location="https://api.example.com/soap/order/v1"/>
        </port>

        <port name="OrderSoap12Port" binding="tns:OrderSoap12Binding">
            <soap12:address location="https://api.example.com/soap/order/v1"/>
        </port>

        <!-- 测试环境(常见做法) -->
        <port name="OrderSoap11TestPort" binding="tns:OrderSoap11Binding">
            <soap:address location="https://test-api.example.com/soap/order/v1"/>
        </port>
    </service>

</definitions>

所有 WSDL 1.1 合法顶级元素(完整清单)

元素是否必须说明
definitions必须根元素
import可选导入别的 WSDL
types可选数据类型定义(XSD)
message必须输入输出消息
portType必须抽象接口
binding必须协议绑定(SOAP/HTTP/MIME 等)
service必须部署地址
documentation可选人类可读的说明(可出现在任何地方)

掌握上面这个模板,你已经可以手写或看懂市面上 99.9% 的企业级 WSDL 了(银行、税务、运营商、医保全是这个结构)。

需要我再给你:

  • 完整带 WS-Security、MTOM、Header、Fault、数组、继承的超级复杂版
  • WSDL 2.0 完整语法对比
  • 用 Java/Spring Boot/.NET 自动生成这个完整 WSDL 的代码
    直接说一声!
文章已创建 2965

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部