【问题标题】:generated WSDL have no Operations in Contract-First approach SOAP WS with Spring-boot生成的 WSDL 在 Contract-First 方法中没有操作 带有 Spring-boot 的 SOAP WS
【发布时间】:2019-09-09 04:49:38
【问题描述】:

我按照本教程中的步骤进行操作:1 https://dzone.com/articles/creating-a-soap-web-service-with-spring-boot-start

但是在我运行代码并获取 wsdl 之后,wsdl 没有任何操作就来了。我缺少什么?

应该有一个带有操作的 WSDL,所以我可以在 SoapUi 上使用它,有什么帮助吗?提前致谢

这是我的xsd

<xs:complexType name="requestHeader">
    <xs:sequence>
        <xs:element name="ServiceName" type="xs:string"/>
        <xs:element name="SystemName" type="xs:string"/>
        <xs:element name="Operation" type="xs:string"/>
        <xs:element name="RequestId" type="xs:string"/>
        <xs:element name="RequestTimestamp" type="xs:string"/>
    </xs:sequence>
</xs:complexType>
<xs:complexType name="userRequestBody">
    <xs:sequence>
        <xs:element name="UserFullName" type="xs:string"/>
        <xs:element name="UserLoginName" type="xs:string"/>
        <xs:element name="UserEmail" type="xs:string"/>
        <xs:element name="MobileNumber" type="xs:string"/>
        <xs:element name="UserType" type="xs:string"/>
        <xs:element name="OrgName" type="xs:string"/>
        <xs:element name="BranchCode" type="xs:string"/>
        <xs:element name="UserGroups" type="xs:string"/>
    </xs:sequence>
</xs:complexType>

<xs:element name="UsersManagementReq">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="requestHeader" type="tns:requestHeader"/>
            <xs:element name="userRequestBody" type="tns:userRequestBody"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>



<xs:complexType name="responseHeader">
    <xs:sequence>
        <xs:element name="ServiceName" type="xs:string"/>
        <xs:element name="SystemName" type="xs:string"/>
        <xs:element name="Operation" type="xs:string"/>
        <xs:element name="RequestId" type="xs:string"/>
        <xs:element name="RequestTimestamp" type="xs:string"/>
    </xs:sequence>
</xs:complexType>
<xs:complexType name="creationResponseBody">
    <xs:sequence>
        <xs:element name="UserFullName" type="xs:string"/>
        <xs:element name="UserLoginName" type="xs:string"/>
        <xs:element name="UserEmail" type="xs:string"/>
        <xs:element name="MobileNumber" type="xs:string"/>
        <xs:element name="UserType" type="xs:string"/>
        <xs:element name="OrgName" type="xs:string"/>
        <xs:element name="BranchCode" type="xs:string"/>
        <xs:element name="UserGroups" type="xs:string"/>
        <xs:element name="UserRoles" type="xs:string"/>
        <xs:element name="ErrorCode" type="xs:string"/>
        <xs:element name="ErrorDescription" type="xs:string"/>
    </xs:sequence>
</xs:complexType>

<xs:element name="UsersManagementRes">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="responseHeader" type="tns:responseHeader"/>
            <xs:element name="creationResponseBody" type="tns:creationResponseBody"/>
        </xs:sequence>
    </xs:complexType>
</xs:elem

ent>

端点:

package com.example.demo;


import com.howtodoinjava.xml.school.CreationResponseBody;
import com.howtodoinjava.xml.school.UsersManagementRes;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;

import javax.swing.*;

@Endpoint
public class StudentDetailsEndpoint {


@PayloadRoot(namespace = "http://www.howtodoinjava.com/xml/school", localPart = "UsersManagementReq")
@ResponsePayload
public UsersManagementRes processCourseDetailsRequest(@RequestPayload UsersManagementRes request) {
    UsersManagementRes response = new UsersManagementRes();
    CreationResponseBody creationResponseBody = new CreationResponseBody();
    creationResponseBody.setUserEmail("Salim Alismaili");
    UsersManagementRes usersManagementRes = new UsersManagementRes();
    usersManagementRes.setCreationResponseBody(creationResponseBody);
    return response;}}

WS 配置:

package com.example.demo;


import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;

@EnableWs
@Configuration
public class WebServiceConfig {
    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext context) {
        MessageDispatcherServlet messageDispatcherServlet = new MessageDispatcherServlet();
        messageDispatcherServlet.setApplicationContext(context);
        messageDispatcherServlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(messageDispatcherServlet, "/ws/*");
    }
    @Bean
    public XsdSchema studentsSchema() {
        return new SimpleXsdSchema(new ClassPathResource("users.xsd"));
    }

    @Bean(name = "users")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema studentsSchema) {
        DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
        definition.setPortTypeName("UsersManagementReq");
        definition.setTargetNamespace("http://www.howtodoinjava.com/xml/school");
        definition.setLocationUri("/ws");
        definition.setSchema(studentsSchema);
        return definition;
    }


}

【问题讨论】:

    标签: java spring-boot web-services soap


    【解决方案1】:

    在您的 xsd 文件中将元素“UsersManagementRes”更改为“UsersManagementRequest”。

    旧:

    <xs:element name="UsersManagementRes">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="responseHeader" type="tns:responseHeader"/>
                <xs:element name="creationResponseBody" type="tns:creationResponseBody"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    

    新:

    <xs:element name="UsersManagementRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="responseHeader" type="tns:responseHeader"/>
                <xs:element name="creationResponseBody" type="tns:creationResponseBody"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    

    注意:您还需要指定/创建以“...Response”结尾的响应元素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-19
      • 2014-04-10
      • 1970-01-01
      相关资源
      最近更新 更多