2012-12-04 58 views
1

我正在嘗試使用Savon將SOAP Key元素添加到SOAP標頭,但是我正在爭奪一場失敗的戰鬥。我對Ruby相當陌生,而我所知道的是自我教導。根據他們的API文檔,我需要添加: 此ProductServe函數將返回(SOAP-Header)身份驗證元素,並且必須隨每個請求一起發送。Ruby Savon設置SOAP標頭元素

參數

Required Name  Type Description        Min Occurs Max Occurs 
No  sToken string Unique token to identify visitor.  0   1 
Yes  sApiKey string User specific key to authenticate user. 1   1 

http://wiki.affiliatewindow.com/index.php/UserAuthentication

我沒有設法找到任何類似我想要做的,這是我試過的代碼:

endpoint = "http://v3.core.com.productserve.com/ProductServeService.wsdl" 
client = Savon.client 

response = client.request :urn, "getCategory" do 
    soap.endpoint = endpoint 
    soap.header = { 
    "urn:sApiKey" => "xxxx" 
    } 
end 

任何幫助將不勝感激!

+0

無恥請那兒剽竊創建一個示例請求(可以使用的soapUI爲該)或提供的wsdl作爲要旨或pastie。 – rubiii

+0

我瞎了:)這一點去@LazyMonkey – rubiii

+0

我得到錯誤:「薩翁::客戶端#請求至少需要一個參數」,但有代碼: response = client.request:urn,「 getProductList「do soap.endpoint = endpoint soap.header = {」sApiKey「=>」test「} end 我知道這與orignal問題無關,因爲你已經在這裏回覆:) – skeniver

回答

1

看起來你需要配置薩翁客戶端:

client = Savon::Client.new do 
    wsdl.document = endpoint 
    wsdl.element_form_default = :unqualified 
end 

我做了這些改變,你的代碼的其餘部分返回有效SOAP響應。

this question

+0

感謝一百萬先生們! – skeniver

相關問題