2014-09-24 156 views
1

我嘗試使用savon-gem通過SOAP登錄Affili.net。SOAP Ruby On Rails登錄Affili.net

client = Savon.client do 
    wsdl "https://api.affili.net/V2.0/Logon.svc?wsdl" 
    end 

    message =  { 
    'Username' => '123123', 
    'Password' => '123123', 
    'ins2:WebServiceType' => 'Publisher' } 

    response = client.call(:logon, :message => message) 

但我只得到此異常:

(a:DeserializationFailed) The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://affilinet.framework.webservices/Svc:LogonRequestMsg. The InnerException message was 'Error in line 1 position 777. 'EndElement' 'LogonRequestMsg' from namespace 'http://affilinet.framework.webservices/Svc' is not expected. Expecting element 'Username | Password | WebServiceType'.'. Please see InnerException for more details. 

https://developer-api.affili.net/V2.0/Logon.svc?wsdl

的哪些錯誤?

更新

現在,我嘗試了一些工具,像這樣:

http://www.soapclient.com/soapclient?template=%2Fclientform.html&fn=soapform&SoapTemplate=%2FSoapResult.html&SoapWSDL=https%3A%2F%2Fdeveloper-api.affili.net%2FV2.0%2FLogon.svc%3Fwsdl&_ArraySize=2

而且還告訴我:這是行不通的。但我的帳戶和憑據都可以!

所以我試圖在PHP

define ("WSDL_LOGON", "https://api.affili.net/V2.0/Logon.svc?wsdl"); 
define ("WSDL_STATS", "https://api.affili.net/V2.0/PublisherStatistics.svc?wsdl"); 

$Username = '123123'; // the publisher ID 
$Password = '123123'; // the publisher web services password 

$SOAP_LOGON = new SoapClient(WSDL_LOGON); 
$Token  = $SOAP_LOGON->Logon(array(
      'Username' => $Username, 
      'Password' => $Password, 
      'WebServiceType' => 'Publisher' 
      )); 
echo $Token; 

和它的作品!

所有在線工具,所有離線工具和Ruby on Rails和PHP有什麼區別?

回答

0

嘗試發送message與符號鍵,這樣的:

message = { 
    logon: { 
     username: '123123', 
     password: '123123', 
     web_service_type: 'Publisher' 
    } 
    } 
+0

不會改變任何東西 – Paket2001 2014-09-24 14:22:53

+0

@ Paket2001如果添加命名空間'logon'或'logon_request'(更新我的答案) – itsnikolay 2014-09-24 14:29:16

+0

這是一個好主意嘗試它象徵,但它不起作用。 WSDL告訴我可以像我一樣嘗試使用msg。 – Paket2001 2014-09-26 09:33:37

0

我還是不知道薩翁(2.7.2)和PHP實現之間的差異。

但對於affili.net的解決方案通過使用薩翁3(但還不穩定!)

client = Savon.new("https://api.affili.net/V2.0/Logon.svc?wsdl") 

logon_body = { 
    LogonRequestMsg: { 
    'Username' => '123123', 
    'Password' => '123123', 
    'WebServiceType' => 'Publisher' 
    } 
} 

operation = client.operation('Authentication', 'DefaultEndpointLogon', 'Logon') 
operation.body = logon_body 
response = operation.call 

puts response.body[:credential_token] 

一些薩翁3文檔:http://savonrb.com/version3/getting-started.html

而GitHub的分支: https://github.com/savonrb/savon/tree/version3