繁体   English   中英

生成的 WSDL 在 Contract-First 方法中没有操作 SOAP WS with Spring-boot

[英]generated WSDL have no Operations in Contract-First approach SOAP WS with Spring-boot

我按照本教程中的步骤操作: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;
    }


}

将 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”结尾的响应元素。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM