【发布时间】:2023-03-22 01:27:01
【问题描述】:
我是使用 spring 进行 SOAP webservices 开发的新手,我已经参考了以下网站进行我的 soap ws 开发。https://www.concretepage.com/spring-boot/spring-boot-soap-web-service-example。我已经设置了可以生成 wsdl 文件的演示应用程序。但是,当我使用与项目相关的 XSD 文件时,它会生成 wsdl 文件,但它在 wsdl:portType 部分下不包含任何内容。
我已经使用下面的xsd文件来生成基于DefaultWsdl11Definition的wsdl。我的 xsd 文件在这里。
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.com/"
targetNamespace="http://www.example.com/" elementFormDefault="qualified">
<xs:simpleType name="StatusCode">
<xs:restriction base="xs:string">
<xs:enumeration value="OK"/>
<xs:enumeration value="REQUEST_ERROR"/>
<xs:enumeration value="APPLICATION_ERROR"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="PatientStatus">
<xs:sequence>
<xs:element name="errorDescription" nillable="true" type="xs:string"/>
<xs:element name="statusCode" type="tns:StatusCode"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="parameters">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="parameter">
<xs:complexType>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="value" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="createCaseForPatientRequestBody">
<xs:complexType>
<xs:sequence>
<xs:element name="caseId" nillable="true" type="xs:string"/>
<xs:element name="caseXML" nillable="false" type="xs:string"/>
<xs:element minOccurs="0" name="entityType" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="entityInstance" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="parameters" nillable="true" type="tns:parameters"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="createCaseForPatientSResponseBody">
<xs:complexType>
<xs:sequence>
<xs:element name="caseId" nillable="true" type="xs:string"/>
<xs:element name="screensURL" nillable="true" type="xs:string"/>
<xs:element name="patientStatus" nillable="false" type="tns:PatientStatus"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
请纠正我做错的地方。我一直在试图找出问题所在。请帮忙。提前致谢。
终点
private static final String NAMESPACE_URI = "http://www.example.com/";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "createCaseForPatient")
@ResponsePayload
public createCaseForPatientResponse createCase(@RequestPayload createCaseForPatientRequest request) {
createCaseForPatientResponse response = new createCaseForPatientResponse();
response.setCaseId("ABC123");
response.setScreensURL("www.patientinfo.org");
response.setPatientStatus("ACTIVE")
return response;
}
wsconfig.java
public class WSConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/soapws/*");
}
@Bean(name = "articles")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema articlesSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("ArticlesPort");
wsdl11Definition.setLocationUri("/soapws");
wsdl11Definition.setTargetNamespace("http://www.example.com/");
wsdl11Definition.setSchema(articlesSchema);
return wsdl11Definition;
}
@Bean
public XsdSchema articlesSchema() {
return new SimpleXsdSchema(new ClassPathResource("xsd/articles.xsd"));
}
}
【问题讨论】:
-
您必须提供有关您所做工作的更多信息。你能发布你的端点(用@Endpoint注释的类)定义吗?
-
和你的配置更新(WSConfig 类)
-
@AkliREGUIG - 我已经更新了端点和 wsconfig 文件供您参考。
标签: spring-boot soap spring-ws jaxb2