You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于已有SOAP服务生成完整WSDL的问题求助(Spring WebServices)

问题解决方案

一、WSDL缺少操作及请求/响应描述的解决步骤

1. 修正Endpoint注解配置

确保代理服务的Endpoint类和方法使用正确的Spring WS注解,绑定请求/响应的命名空间与元素:

@Endpoint
public class SoapProxyEndpoint {
    // 与目标SOAP服务、XSD定义的命名空间保持完全一致
    private static final String TARGET_NAMESPACE = "http://your-target-service.com/soap";

    @PayloadRoot(namespace = TARGET_NAMESPACE, localPart = "ProxyRequest")
    @ResponsePayload
    public ProxyResponse handleProxyRequest(@RequestPayload ProxyRequest request) {
        // 这里实现请求转发到目标SOAP服务的逻辑
        return targetSoapClient.invoke(request);
    }
}

2. 完善WSDL定义配置

在Spring WS配置类中,通过DefaultWsdl11Definition明确关联XSD、设置端口与服务信息,确保WSDL生成完整操作:

@Configuration
@EnableWs
public class WebServiceProxyConfig extends WsConfigurerAdapter {

    @Bean(name = "proxyServiceWsdl")
    public DefaultWsdl11Definition proxyWsdlDefinition(XsdSchema proxySchema) {
        DefaultWsdl11Definition wsdlDefinition = new DefaultWsdl11Definition();
        wsdlDefinition.setPortTypeName("ProxyServicePort");
        wsdlDefinition.setLocationUri("/soap-proxy"); // 服务访问路径
        wsdlDefinition.setTargetNamespace(TARGET_NAMESPACE);
        wsdlDefinition.setSchema(proxySchema);
        return wsdlDefinition;
    }

    @Bean
    public XsdSchema proxySchema() {
        // 确保XSD文件包含请求、响应元素的完整定义
        return new SimpleXsdSchema(new ClassPathResource("proxy-service-schema.xsd"));
    }
}

3. 校验命名空间一致性

  • Endpoint的@PayloadRoot命名空间必须与XSD的targetNamespace、WsdlDefinition的targetNamespace完全一致(包括大小写、路径后缀)
  • XSD中需明确定义请求、响应元素,例如:
<xs:schema targetNamespace="http://your-target-service.com/soap" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="ProxyRequest">
        <xs:complexType>
            <!-- 请求参数定义 -->
        </xs:complexType>
    </xs:element>
    <xs:element name="ProxyResponse">
        <xs:complexType>
            <!-- 响应参数定义 -->
        </xs:complexType>
    </xs:element>
</xs:schema>

二、SoapUI导入时message.xsd加载过早结束的解决步骤

1. 检查XSD完整性与语法

  • 用XML校验工具(如IDEA内置XML校验)检查XSD是否存在未闭合标签、无效引用、命名空间错误
  • 直接访问WSDL中引用的XSD URL(例如http://localhost:8080/soap-proxy/proxyServiceWsdl?xsd=1),确认返回的XSD内容完整、无截断

2. 处理XSD依赖引用

如果XSD中包含<xs:import>或<xs:include>,需用CommonsXsdSchemaCollection统一管理依赖:

@Bean
public XsdSchemaCollection proxySchemaCollection() {
    CommonsXsdSchemaCollection schemaCollection = new CommonsXsdSchemaCollection(
            new ClassPathResource("base-schema.xsd"),
            new ClassPathResource("proxy-service-schema.xsd")
    );
    schemaCollection.setInline(true); // 允许XSD内联,避免SoapUI加载外部依赖失败
    return schemaCollection;
}

然后在DefaultWsdl11Definition中替换为wsdlDefinition.setSchemaCollection(proxySchemaCollection());

3. 调整SoapUI加载配置

  • 导入WSDL时,将“Connection Timeout”和“Socket Timeout”调至30000ms以上
  • 关闭“Follow Redirects”选项,避免重定向导致的加载中断
  • 若服务端部署在本地,优先使用http://localhost而非IP地址访问WSDL

4. 排查服务端响应问题

  • 检查Tomcat/Undertow等容器的响应缓冲区设置,避免大XSD被截断
  • 确保Spring WS依赖版本与Spring Boot版本匹配(例如Spring Boot 2.7.x对应spring-ws-core 3.1.x)

内容的提问来源于stack exchange,提问作者Prototype

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 10:37:32