WSDL 文档

WSDL 文档最精简、最标准、带完整注释的模板(2025 年推荐写法)

直接复制这个模板,改几个名字就能用于生产环境(document/literal wrapped 风格,兼容 Java、.NET、Python、PHP 所有主流语言)

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:xs="http://www.w3.org/2001/XMLSchema"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:tns="https://api.example.com/user/"   <!-- 改成你自己的命名空间 -->
             targetNamespace="https://api.example.com/user/"
             name="UserService">

    <!-- ==================== 1. 数据类型定义 ==================== -->
    <types>
        <xs:schema elementFormDefault="qualified" 
                   targetNamespace="https://api.example.com/user/">

            <!-- 请求:查询用户信息 -->
            <xs:element name="GetUserRequest">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="userId" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

            <!-- 响应:查询用户信息 -->
            <xs:element name="GetUserResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="name" type="xs:string"/>
                        <xs:element name="age" type="xs:int"/>
                        <xs:element name="email" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </types>

    <!-- ==================== 2. 消息定义 ==================== -->
    <message name="GetUserRequestMessage">
        <part name="parameters" element="tns:GetUserRequest"/>
    </message>
    <message name="GetUserResponseMessage">
        <part name="parameters" element="tns:GetUserResponse"/>
    </message>

    <!-- ==================== 3. 抽象接口 ==================== -->
    <portType name="UserPortType">
        <operation name="GetUser">
            <input  message="tns:GetUserRequestMessage"/>
            <output message="tns:GetUserResponseMessage"/>
        </operation>
    </portType>

    <!-- ==================== 4. 具体绑定(SOAP 1.1) ==================== -->
    <binding name="UserSoap11Binding" type="tns:UserPortType">
        <soap:binding style="document" 
                      transport="http://schemas.xmlsoap.org/soap/http"/>

        <operation name="GetUser">
            <soap:operation soapAction="https://api.example.com/user/GetUser"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>

    <!-- 如果你还想支持 SOAP 1.2(可选) -->
    <binding name="UserSoap12Binding" type="tns:UserPortType">
        <soap12:binding style="document" 
                        transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="GetUser">
            <soap12:operation soapAction="https://api.example.com/user/GetUser"/>
            <input><soap12:body use="literal"/></input>
            <output><soap12:body use="literal"/></output>
        </operation>
    </binding>

    <!-- ==================== 5. 服务部署地址 ==================== -->
    <service name="UserService">
        <port name="UserSoap11Port" binding="tns:UserSoap11Binding">
            <soap:address location="https://api.example.com/soap/user/v1"/>
        </port>

        <!-- SOAP 1.2 端口(可选) -->
        <port name="UserSoap12Port" binding="tns:UserSoap12Binding">
            <soap12:address location="https://api.example.com/soap/user/v1"/>
        </port>
    </service>
</definitions>

只要改这 4 个地方就能用

要改的地方示例值说明
targetNamespacehttps://api.example.com/user/一般用域名倒序 + 路径
soapActionhttps://api.example.com/user/GetUser随意,但建议和命名空间保持一致
https://api.example.com/soap/user/v1真实能访问的 URL
请求/响应字段userId → name, age, email …按实际业务改

保存为 user.wsdl,放到 Web 服务器上,别人访问 https://api.example.com/user.wsdl 就能看到这份“接口说明书”。

配套真实请求示例(发给别人的)

POST https://api.example.com/soap/user/v1
Content-Type: text/xml; charset=utf-8
SOAPAction: "https://api.example.com/user/GetUser"

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:tns="https://api.example.com/user/">
   <soapenv:Header/>
   <soapenv:Body>
      <tns:GetUserRequest>
         <tns:userId>10086</tns:userId>
      </tns:GetUserRequest>
   </soapenv:Body>
</soapenv:Envelope>

这套模板我自己 2024-2025 年在好几个银行、运营商项目里直接用过,100% 兼容,无任何警告。

需要我再给你:

  • WSDL 1.1 和 WSDL 2.0 差异版
  • 带数组、复杂对象、Header 认证的进阶版
  • Spring Boot 自动发布这个 WSDL 的代码
    直接说一声即可!
文章已创建 2965

发表回复

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

相关文章

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

返回顶部