简体   繁体   English

使用Ruby Savon客户端连接到PHP NuSOAP服务器

[英]Connecting to PHP NuSOAP server with Ruby Savon client

I'm trying to connect to a remote SOAP service, which has been set up with the PHP NuSoap library. 我正在尝试连接到已通过PHP NuSoap库设置的远程SOAP服务。 I'm connecting using a Ruby Savon client. 我正在使用Ruby Savon客户端进行连接。

Visiting the service's WDSL address ( http://example.com/api/webservice.php?wdsl ) gives the following information about the end point I'm trying to use: 访问服务的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:

Setting up my Savon client like so: 像这样设置我的Savon客户:

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

and then trying to call the 'add subscription' method: 然后尝试调用“添加订阅”方法:

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

gives the following error in the logs - 在日志中给出以下错误-

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

Setting up the client like so: 像这样设置客户端:

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

and then running the same call as above raises a Savon::SOAPFault error, which I'm assuming would be due to the lack of a namespace attribute (I'm not sure how to further debug/glean information from this error)? 然后运行与上面相同的调用会引发Savon :: SOAPFault错误,我认为这是由于缺少名称空间属性(我不确定如何从此错误中进一步调试/收集信息)引起的?

Based on the information above, how should I configure the Savon client to connect to this service? 根据以上信息,我应该如何配置Savon客户端以连接到该服务?

Edit: 编辑:

Setting up the client like so - 这样设置客户-

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

and then calling (with a populated message_hash var) 然后调用(使用填充的message_hash var)

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

spits out the following error: 吐出以下错误:

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>'

It looks like you're on an outdated Savon version < 2.x. 看来您使用的是版本低于2.x的Savon版本。 I recommend to upgrade to version 2.x (2.11.1 as I'm writing). 我建议升级到2.x版(在撰写本文时为2.11.1)。 The interface changed considerably with the introduction of v2. 随着v2的引入,界面发生了很大变化。

A minimal implementation could look like this: 一个最小的实现可能看起来像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM