Spring-WS client not setting SOAPAction header

后端 未结 3 1190
迷失自我
迷失自我 2020-12-08 08:08

I\'m sending a SOAP request and the server is complaining that the SOAPAction header is empty. I think I\'m setting it right, but obviously I\'m not. Wireshark shows it\'s

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 09:06

    A complete answer goes as follow.

    While you are using WebServiceTemplate as a class to communicate with the Webservice, I do not understand why but it does not properly fill the HTTP Header.

    Some WSDL have a part saying:

    
    

    And the WebServiceTemplate ignores this part. The above error means that your soapAction parameter in the header is empty. And it should be not. Check with Wireshark. I did - using some Chrome Soap client and Spring. The second one has an invalid header.


    To fix this you need to follow Section 6.2.4 in here: http://docs.spring.io/spring-ws/sites/2.0/reference/html/client.html

    What it says is basically add the header part on your own, with WebServiceMessageCallback interface. You can read more in the reference.

    Basically it ends up like this:

     webServiceTemplate.marshalSendAndReceive(o, new WebServiceMessageCallback() {
    
        public void doWithMessage(WebServiceMessage message) {
            ((SoapMessage)message).setSoapAction("http://tempuri.org/Action");
        }
    });
    

    Where you can set up properly the header value. Worked for me too. Whole day of reading.

提交回复
热议问题