【发布时间】:2016-04-22 20:01:06
【问题描述】:
我正在尝试连接到使用 PHP NuSoap 库设置的远程 SOAP 服务。我正在使用 Ruby Savon 客户端进行连接。
访问服务的 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:
像这样设置我的 Savon 客户端:
client = Savon::Client.new(wsdl: "http://www.example.com/api/webservice.php?wdsl")
然后尝试调用“添加订阅”方法:
response = client.call(:addsubscription) do
message my_hash_of_stuff
end
在日志中给出以下错误 -
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
然后运行与上面相同的调用会引发 Savon::SOAPFault 错误,我假设这是由于缺少命名空间属性(我'不确定如何从这个错误中进一步调试/收集信息)?
根据以上信息,我应该如何配置 Savon 客户端以连接到该服务?
编辑:
像这样设置客户端 -
client = Savon.client(namespace: '', endpoint: 'http://www.example.com/api/webservice.php')
然后调用(使用填充的 message_hash 变量)
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>'
【问题讨论】:
-
我以为你没有真的打电话给
http://www.example.com/api/webservice.php?wdsl,是吗?那只是你的占位符? -
另外:如果您打开登录 Savon 客户端,您可能会获得更好的信息,了解出了什么问题。 WSDL 看起来如何?您发布的不是 WSDL,而是其他一些伪代码 (?) 文档。我刚刚注意到文档中有一个
style: rpc暗示它不是 SOAP??