2014-03-27 60 views
0

所以XML請求字符串我進入薩翁client.call是如下(注意這個工程,我得到迴應):薩翁消息請求

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/" 
xmlns:mun="http://schemas.datacontract.org/2004/07/External.Service.Bo"> 
    <soap:Header/> 
    <soap:Body> 
     <tem:GetInformationsForCoordinates> 
     <tem:coordReq> 
      <mun:Coordinates> 
       <mun:Coordinate> 
        <mun:Id>1</mun:Id> 
        <mun:QualityIndex>90</mun:QualityIndex> 
        <mun:X>-110.5322</mun:X> 
        <mun:Y>35.2108</mun:Y> 
       </mun:Coordinate> 
      </mun:Coordinates> 
     </tem:coordReq> 
     <tem:analysisTypes> 
      <mun:AnalysisType>Additional</mun:AnalysisType> 
     </tem:analysisTypes> 
     </tem:GetInformationsForCoordinates> 
    </soap:Body> 
</soap:Envelope> 

而不是通過在作爲XML這是不確實可行我想傳遞一個消息,所以我可以添加多個(可能的座標的陣列),多個分析類型容易等

Ruby代碼我不得不這樣做到目前爲止是:

coordinate = { Id: '1', QualityIndex: 90, X: -110.5322, Y: 35.2108} 
    coordinates = {Coordinates: [coordinate] } 
    coordinateReq = {coordReq: {coordinates: coordinates} } 

然後我通過coor dinateReq到client.call - 我可以在Ruby中看到下面安慰產生的請求:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:tns="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <env:Body> 
    <tns:GetInformationsForCoordinates> 
     <coordReq> 
     <coordinates> 
      <Coordinates> 
      <Id>1</Id> 
      <QualityIndex>90</QualityIndex> 
      <X>-110.5322</X> 
      <Y>35.2108</Y> 
      </Coordinates> 
     </coordinates> 
     </coordReq> 
    </tns:GetInformationsForCoordinates> 
    </env:Body> 
</env:Envelope> 

有幾個問題 - 有沒有方法可以讓我的namespance門添加到類似於我絃斷XML正確的屬性(即Id/QualityIndex等)。在我的例子中,用Ruby代碼座標是小寫,然後座標是大寫,而它應該是大寫,但不是複數。最後,我需要包含分析類型(注意小寫字母大寫T),然後是AnalysisType,其中可能有多個請求,並且AnalysisType也需要mun命名空間。

+0

你可以嘗試通過這些選項:'element_form_default:qualified','namespace_identifier:mun'到薩翁客戶端。 – Magnuss

回答

0

,而不是像

QualityIndex: 90 

你需要指定像

'mun:QualityIndex' => 90 
+0

好吧生病嘗試,謝謝Steffen ...然後我需要添加mun作爲第二個命名空間吧?當我把它作爲第二個命名空間添加時,我得到它在GetInformationForCoordinates節點上拾取,這是不正確的,因爲它需要是tns名稱空間 –

1

工作了字符串使用斯特芬的解答一個符號 - 只有一點要注意的是,因爲我在我的評論我也提到必須添加名稱空間,如下所示(以防萬一其他人遇到此問題:

namespaces = { 
    "xmlns:mun" => "http://schemas.datacontract.org/2004/07/External.Service.Bo" 
    } 

然後在Savon.client以下(注意命名空間線的關鍵之一:

client = Savon.client(wsdl: WSDL_URL, 
         log: true, # set to true to switch on logging 
         namespaces: namespaces, 
         #etc more config set up