2012-06-27 41 views
0

我目前正在嘗試使用Rails 2.3.8,Savon和OX的SOAP API爲Open-Xchange的本地實例構建一種配置服務。在Savon中執行XML結構順序

通過控制檯,我可以發出下列可以工作的命令;

>> client = Savon::client("http://192.168.2.195/servlet/axis2/services/OXContextService?wsdl") 
=> #<Savon::Client:0x2b5151bad790 @wsdl=#<Savon::Wasabi::Document:0x2b5151bad678 @document="http://192.168.2.195/servlet/axis2//services/OXContextService?wsdl", @request=#<HTTPI::Request:0x2b5151bad628>>, @http=#<HTTPI::Request:0x2b5151bad628>, @config=#<struct Savon::Config _logger=#<Savon::Logger:0x2b5151bad6c8 @device=#<IO:0x2b514a775ad0>>, pretty_print_xml=nil, raise_errors=true, soap_version=1, env_namespace=nil, soap_header=nil>> 
>> client.request :list_by_database do 
?> soap.body = { 
?> :auth => { 
?> :login => "oxadminmaster", 
?> :password => "admin_master_password" 
>> }, 
?> :db => { 
?> :id => 3 
>> } 
>> } 
>> end 
HTTPI executes HTTP GET using the net_http adapter 
SOAP request: https://192.168.2.195/servlet/axis2/services/OXContextService.OXContextServiceHttpsSoap11Endpoint/ 
SOAPAction: "urn:listByDatabase", Content-Type: text/xml;charset=UTF-8, Content-Length: 657 
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ins0="http://soap.admin.openexchange.com" xmlns:ns="http://soap.admin.openexchange.com" xmlns:ins1="http://dataobjects.soap.admin.openexchange.com/xsd" xmlns:ins2="http://dataobjects.rmi.admin.openexchange.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><ins0:listByDatabase><ins0:db><ins1:id>3</ins1:id></ins0:db><ins0:auth><ins2:login>oxadminmaster</ins2:login><ins2:password>admin_master_password</ins2:password></ins0:auth></ins0:listByDatabase></env:Body></env:Envelope> 
HTTPI executes HTTP POST using the net_http adapter 
warning: peer certificate won't be verified in this SSL session 
SOAP response (status 200): 

它的工作原理,沒有問題。然而,當我嘗試下面的代碼...

class Ox_Context_Service 
    extend Savon::Model 

    attr_accessor :data, :returnCode 

    document "http://192.168.2.195/servlet/axis2/services/OXContextService?wsdl" 

    def list_by_database oxMasterUser, oxMasterPassword 
    begin 
    response = client.request :list_by_database do 
     soap.body = { 
     :auth => { 
      #for the sake of testing 
      :login => "#{oxMasterUser}", 
      :password => "#{oxMasterPassword}" 
     }, 
     :db => { 
      :id => 3 
      #For the sake of testing 
     } 
     } 
     end 
     if response.success? 
     data = response.body[:list_by_database_response][:return] 
     if data 
      @data = data 
      @returnCode = "#{response.http.code}" 
     end 
     end 
    end 
    rescue Savon::Error => fault 
    @data = {} 
    @returnCode = "#{fault}" 
    end 
end 

使用下面的捲曲...

curl localhost:4545/oxContextService/list_by_database -d 'oxUsername=oxadminmaster' -d 'oxPassword=admin_master_password'

我得到...

HTTPI executes HTTP GET using the net_http adapter 
SOAP request: https://192.168.2.195/servlet/axis2/services/OXContextService.OXContextServiceHttpsSoap11Endpoint/ 
SOAPAction: "urn:listByDatabase", Content-Type: text/xml;charset=UTF-8, Content-Length: 657 
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ins0="http://soap.admin.openexchange.com" xmlns:ns="http://soap.admin.openexchange.com" xmlns:ins1="http://dataobjects.soap.admin.openexchange.com/xsd" xmlns:ins2="http://dataobjects.rmi.admin.openexchange.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><ins0:listByDatabase><ins0:auth><ins2:login>oxadminmaster</ins2:login><ins2:password>admin_master_password</ins2:password></ins0:auth><ins0:db><ins1:id>3</ins1:id></ins0:db></ins0:listByDatabase></env:Body></env:Envelope> 
HTTPI executes HTTP POST using the net_http adapter 
warning: peer certificate won't be verified in this SSL session 
SOAP response (status 500): 
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>Authentication failed</faultstring><detail /></soapenv:Fault></soapenv:Body></soapenv:Envelope> 

所以 - 兩個相同電話,兩個不同的結果。這裏可能會出錯,所以呢?

編輯:因爲驗證塊首先被送到Rails的調用失敗,而不是最後。我認爲新的問題是如何在不明確寫出XML的情況下執行XML結構順序。

回答

0
soap.body = { 
    :auth => { 
     #for the sake of testing 
     :login => "#{oxMasterUser}", 
     :password => "#{oxMasterPassword}" 
    }, 
    :db => { 
     :id => 3 
     #For the sake of testing 
    } 
    :order! => [:db, :auth] 
} 

order!將強制基於該數組的特定順序。獲得的經驗:閱讀手冊。