我很难通过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