英文:
SOAP12 missing soap action - spring
问题
我正在尝试发起一个简单的SOAP请求,但是我遇到了以下错误:
org.springframework.ws.soap.client.SoapFaultClientException: 无法处理缺少有效操作参数的请求。请提供有效的SOAP操作。
我正在使用 soap12
。以下是我的代码:
MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SaajSoapMessageFactory saajSoapMessageFactory = new SaajSoapMessageFactory(msgFactory);
WebServiceTemplate webServiceTemplate = new WebServiceTemplate(saajSoapMessageFactory);
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("packageName");
marshaller.afterPropertiesSet();
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.afterPropertiesSet();
Object response = webServiceTemplate.marshalSendAndReceive("https://www.w3schools.com/xml/tempconvert.asmx", temperature);
我尝试使用 WebServiceMessageCallback
将 Content-Type
设置为 text/xml
,但未被覆盖。
英文:
I am trying to make a simple SOAP request but I am getting this error:
org.springframework.ws.soap.client.SoapFaultClientException: Unable to handle request without a valid action parameter. Please supply a valid soap action.
I am using soap12
. Here is my code:
MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SaajSoapMessageFactory saajSoapMessageFactory = new SaajSoapMessageFactory(msgFactory);
WebServiceTemplate webServiceTemplate = new WebServiceTemplate(saajSoapMessageFactory);
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("packageName");
marshaller.afterPropertiesSet();
webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.afterPropertiesSet();
Object response = webServiceTemplate.marshalSendAndReceive("https://www.w3schools.com/xml/tempconvert.asmx", temperature);
I tried setting Content-Type
with WebServiceMessageCallback
to text/xml but it didn't get overriden.
答案1
得分: 1
我通过添加以下代码找到了解决方案:
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SaajSoapMessageFactory saajSoapMessageFactory = new SaajSoapMessageFactory(messageFactory);
saajSoapMessageFactory.setSoapVersion(SoapVersion.SOAP_12);
saajSoapMessageFactory.afterPropertiesSet();
英文:
I found a solution by adding:
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SaajSoapMessageFactory saajSoapMessageFactory = new SaajSoapMessageFactory(messageFactory);
saajSoapMessageFactory.setSoapVersion(SoapVersion.SOAP_12);
saajSoapMessageFactory.afterPropertiesSet();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论