SOAP12缺少soap action – spring

huangapple go评论67阅读模式
英文:

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);

我尝试使用 WebServiceMessageCallbackContent-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();

huangapple
  • 本文由 发表于 2020年9月25日 18:23:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/64062263.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定