gpt4 book ai didi

java - 生成的 WSDL 在使用 Spring-boot 的契约优先方法 SOAP WS 中没有任何操作

转载 作者:行者123 更新时间:2023-12-02 00:52:15 26 4
gpt4 key购买 nike

我按照本教程中的步骤进行操作: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”结尾。

关于java - 生成的 WSDL 在使用 Spring-boot 的契约优先方法 SOAP WS 中没有任何操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57848019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com