2012-07-24 216 views
5

我很難通過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()); 
      } 
     } 
+0

你似乎在這裏設置SOAP Action頭多種方式 - 使用'actionCallBack',明確使用'新的SoapActionCallback..',都是不行的方法? – 2012-07-24 13:52:15

+0

那是正確的。這兩種方法都給出了相同的錯誤。 – user1546703 2012-07-24 14:01:04

+0

你需要一個'http:// networksolutions.com/ReadOrder'標題 - 你使用wireshark通過電報看到了什麼標題。只是想確保你沒有發送'https:// ecomapi.networksolutions.com/soapservice.asmx'。這是一個簡單的工具來捕捉來回的內容 - http://sourceforge.net/projects/nettool/ – 2012-07-24 14:04:49

回答

1

我面臨同樣的問題,我跟蹤回一個錯誤的1.3.2版本的com.sun.xml.messaging.saaj.soap.MessageImpl實現(http://java.net/jira/browse/SAAJ-37)。 我升級到1.3.19版本,一切都很好。

的問題: -

寫入請求輸出流之前,()方法被調用調用SaveChanges。該類的1.3.2版本在'saveChanges'方法的實現中覆蓋'Content-Type'請求頭。

0

我有一個類似的問題,這是由於package-info.java文件中的XmlSchema註釋的命名空間與我試圖調用的soap服務不同。這是由於我使用xjc從xsd中生成jaxb請求和響應對象,而這些xsd是我從wsdl部件縫製在一起加上來自先前服務的xsd頭部的,我正在進行接口連接,所以這是我的部分的純剪切和粘貼錯誤,但是之前關於命名空間的回答是我迅速提出的錯誤。

0

SOAPAction僅在SOAP 1.1中是必需的,請參閱section Content Type

在SOAP 1.2中已經刪除SOAP 1.1必需的SOAPAction HTTP標頭。其位置是應用程序/ soap + xml媒體類型上的可選操作參數。