我很難通過Spring-ws WebServiceTemplate調用SOAP 1.2 WebService。正在發出的請求在Http Header中缺少SOAPAction,並且服務器拋出一個錯誤,「無法處理沒有有效操作參數的請求,請提供有效的soap動作。」通過wireshark進行監控,我能夠弄清楚SOAP Action缺失。我也不支持任何代理。HTTP頭中缺少Spring WebServiceTemplate SOAPAction
我已經確認,我嘗試發送的SOAP XML通過TCP Mon(SOAP UI之類的工具)運行請求而有效,並且能夠獲得響應。
這裏是我的Spring配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="soapVersion">
<util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12" />
</property>
</bean>
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="messageFactory" />
<property name="defaultUri" value="https://ecomapi.networksolutions.com/soapservice.asmx" />
<property name="messageSender">
<bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender" /> </property>
</bean>
這是我的Java代碼:
public void simpleSendAndReceive() {
try{
StreamSource source = new StreamSource(new StringReader(MESSAGE));
StreamResult result = new StreamResult(System.out);
SoapActionCallback actionCallBack = new SoapActionCallback("https://ecomapi.networksolutions.com/soapservice.asmx") {
public void doWithMessage(WebServiceMessage msg) {
SoapMessage smsg = (SoapMessage)msg;
smsg.setSoapAction("http://networksolutions.com/ReadOrder");
}
};
webServiceTemplate.sendSourceAndReceiveToResult(
"https://ecomapi.networksolutions.com/soapservice.asmx",
source,
new SoapActionCallback("http://networksolutions.com/ReadOrder"),
// actionCallBack,
result);
System.out.println(source.getInputStream().toString());
System.out.println(result.getWriter().toString());
}catch (SoapFaultClientException e) {
System.out.println(e.getFaultCode());
System.out.println(e.getFaultStringOrReason());
System.out.println(e.fillInStackTrace().getLocalizedMessage());
} catch (WebServiceIOException we) {
System.out.println(we.getRootCause());
}
}
你似乎在這裏設置SOAP Action頭多種方式 - 使用'actionCallBack',明確使用'新的SoapActionCallback..',都是不行的方法? – 2012-07-24 13:52:15
那是正確的。這兩種方法都給出了相同的錯誤。 – user1546703 2012-07-24 14:01:04
你需要一個'http:// networksolutions.com/ReadOrder'標題 - 你使用wireshark通過電報看到了什麼標題。只是想確保你沒有發送'https:// ecomapi.networksolutions.com/soapservice.asmx'。這是一個簡單的工具來捕捉來回的內容 - http://sourceforge.net/projects/nettool/ – 2012-07-24 14:04:49