简体   繁体   中英

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

i followed the steps on this tutorial :1 https://dzone.com/articles/creating-a-soap-web-service-with-spring-boot-start

but After i run the code , and get the wsdl , the wsdl coming withoout any operations.. what im missing ?

should have a WSDL with an operation , so i can use it on SoapUi , any help ? thanks in advance

here is my 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>

EndPoint :

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 Configuration :

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;
    }


}

Change element "UsersManagementRes" to "UsersManagementRequest" in your xsd file.

Old:

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

New:

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

Note: You will need to specify/create the response element to end with "...Response" too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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