簡體   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