生成的 WSDL 在带有 Spring 引导的契约优先方法中没有操作 SOAP WS



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

注意:您需要指定/创建以"...回应"也是。

最新更新