我正在使用 Springboot 框架和 eclipse。 我有相关服务的架构 xsd 和 wsdl 文件。 我从 xsd 和 wsdl 创建了 JAXB 类。
在 Java 中使用 Soap xml Web 服务的最佳方法是什么。请找到邮递员请求。 谢谢
<soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/ xmlns:ns=http://service.bi.com/entity/message/2003/ xmlns:ns1=http://service.bi.com/provider/bi/biService/findBIDoc/2003/>
<soapenv:Header>
<ns:BIContext>
<messageId>89</messageId>
<creationTimestamp>2018-07-27T03:56:56.449Z</creationTimestamp>
<hostName>localhost</hostName>
</ns:BIContext>
</soapenv:Header>
<soapenv:Body>
<ns1:findBIDocRequest>
<ns:Version>13</ns:Version>
<docNumber>789999</docNumber>
<userId>test</userId>
<readOnly>true</readOnly>
</ns1:findBIDocRequest>
</soapenv:Body>
</soapenv:Envelope>
谢谢
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
wsimport -keep -verbose http://example.com/yourwsdl?wsdl
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
public class SoapClient extends WebServiceGatewaySupport {
public Object callWebService(String url, Object request){
return getWebServiceTemplate().marshalSendAndReceive(url, request);
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class YourService {
@Autowired
private SoapClient soapClient;
public Object callSoapService() {
Object request = new Object();
return soapClient.callWebService("http://example.com/soapApi", request);
}
}
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
// Set this to the package name of your generated domain objects
marshaller.setContextPath("com.example.soapclient");
return marshaller;
}
@Bean
public WebServiceTemplate webServiceTemplate(Jaxb2Marshaller marshaller) {
WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.setUnmarshaller(marshaller);
// Configure other properties as needed
return webServiceTemplate;
}
// Construct the request object
Object request = new Object(); // Replace with your actual request object
String endpointUrl = "http://example.com/soapService";
// Send the SOAP request
Object response = soapClient.callWebService(endpointUrl, request);
// Process the response as needed