首页 > 解决方案 > 使用 WebServiceTemplate 和 SOAP 发送 HTTP GET 请求

问题描述

我正在尝试使用 WebServiceTemplate 使用 SOAP 向服务器发送 GET 请求,但我无法这样做。如何设置查询参数并发送请求?我尝试构造一个字符串 URL 并使用 marshalSendAndReceive(url, null),但它引发了异常。

我正在使用 Java 和 Spring Boot 来完成这项工作。

result = (TransactionResult) webServiceTemplate.marshalSendAndReceive(uri + "?" + uri2, (Object) null);

错误信息:

Could not create message from InputStream: Unable to create envelope from given source: 

堆栈跟踪

org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Unable to create envelope from given source: ; nested exception is com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to create envelope from given source: 
    at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:216) ~[spring-ws-core-2.4.2.RELEASE.jar:na]
    at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:60) ~[spring-ws-core-2.4.2.RELEASE.jar:na]
    at org.springframework.ws.transport.AbstractWebServiceConnection.receive(AbstractWebServiceConnection.java:92) ~[spring-ws-core-2.4.2.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:611) ~[spring-ws-core-2.4.2.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555) ~[spring-ws-core-2.4.2.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390) ~[spring-ws-core-2.4.2.RELEASE.jar:na]
    at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive

标签: javaspringsoap

解决方案


推荐阅读