2016-04-21 100 views
0

我试图连接到已经使用PHP NuSoap库设置的远程SOAP服务。我正在使用Ruby Savon客户端进行连接。使用Ruby Savon客户端连接到PHP NuSOAP服务器

访问该服务的WDSL地址(http://example.com/api/webservice.php?wdsl)给出了关于终点,我尝试使用以下信息:

Name: addsubscription 
    Binding: webserviceBinding 
    Endpoint: http://www.example.com/api/webservice.php 
    SoapAction: http://www.example.com/api/webservice.php/addsubscription 
    Style: rpc 
    Input: 
    use: encoded 
    namespace: 
    encodingStyle: http://schemas.xmlsoap.org/soap/encoding/ 
    message: addsubscriptionRequest 
    parts: 
    Output: 
    use: encoded 
    namespace: 
    encodingStyle: http://schemas.xmlsoap.org/soap/encoding/ 
    message: addsubscriptionResponse 
    parts: 
    Namespace: 
    Transport: http://schemas.xmlsoap.org/soap/http 
    Documentation: 

设置我的萨翁客户像这样:

client = Savon::Client.new(wsdl: "http://www.example.com/api/webservice.php?wdsl") 

和然后尝试调用“添加订阅”方法:

response = client.call(:addsubscription) do 
    message my_hash_of_stuff 
end 

gi VES在日志下面的错误 -

Savon::UnknownOperationError: Unable to find SOAP operation: :addsubscription 
Operations provided by your service: [] 

设置客户端,像这样:

client = Savon.client do 
    endpoint "http://www.example.com/api/webservice.php" 
    namespace '' 
end 

,然后运行相同的呼叫如上提出了萨翁::的SOAPFault错误,这我假设是由于缺乏名称空间属性(我不知道如何进一步调试/收集此错误中的信息)?

根据以上信息,我应该如何配置Savon客户端连接到此服务?

编辑:

设置客户机像这样 -

client = Savon.client(namespace: '', endpoint: 'http://www.example.com/api/webservice.php') 

,然后调用(用填充message_hash VAR)

response = client.call(:addsubscription, 
        message: message_hash) 

吐出以下错误:

Savon::SOAPFault: /app/vendor/bundle/ruby/2.2.0/gems/nori-2.6.0/lib/nori.rb:72:in `find_value': undefined method `each' for nil:NilClass (NoMethodError) 
from /app/vendor/bundle/ruby/2.2.0/gems/nori-2.6.0/lib/nori.rb:38:in `find' 
from /app/vendor/bundle/ruby/2.2.0/gems/savon-2.11.1/lib/savon/soap_fault.rb:24:in `to_s' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb.rb:498:in `write' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb.rb:498:in `print' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb.rb:498:in `block (2 levels) in eval_input' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb.rb:623:in `signal_status' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb.rb:486:in `block in eval_input' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb/ruby-lex.rb:245:in `block (2 levels) in each_top_level_statement' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb/ruby-lex.rb:231:in `loop' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb/ruby-lex.rb:231:in `block in each_top_level_statement' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb/ruby-lex.rb:230:in `catch' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb/ruby-lex.rb:230:in `each_top_level_statement' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb.rb:485:in `eval_input' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb.rb:395:in `block in start' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb.rb:394:in `catch' 
from /app/vendor/ruby-2.2.3/lib/ruby/2.2.0/irb.rb:394:in `start' 
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start' 
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start' 
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console' 
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!' 
from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>' 
from /app/bin/rails:4:in `require' 
from /app/bin/rails:4:in `<main>' 
+0

我以为你不是真的* *调用'HTTP://www.example.com/api/webservice.php wdsl',你?那只是你的占位符? –

+0

另外:如果你打开登录你的Savon客户端,你可能会得到更好的信息,哪里出了问题。 WSDL是怎样的?您发布的内容不是WSDL,而是其他一些伪代码(?)文档。我只注意到文档中有一个'style:rpc',暗示它不是SOAP? –

回答

0

它看起来像你在过时的萨翁版本< 2.x.我建议升级到版本2.x(2.11.1,因为我正在写)。随着v2的推出,界面发生了很大变化。

最小实现看起来是这样的:

require 'savon' 

WSDL = 'http://www.example.com/api/webservice.php?wdsl' 

client = Savon.client(wsdl: WSDL, 
         log: true, 
         log_level: :debug, 
         pretty_print_xml: true) 
response = client.call(:addsubscription, 
         message: my_hash_of_stuff) 
print response.to_hash 
+0

感谢您的建议,根据我的Gemfile.lock使用了2.11.1,我从这里的文档中提取信息 - http://savonrb.com/version2/client.html - 我已经通过更多的信息更新了这个问题 – user2013350

+0

关于这方面的任何消息? –