我是 Java 世界的新手,我正在使用 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);
}
}