Ruby& Savon SOAP客户端 - 无法找到SOAP操作

时间:2013-08-24 20:04:48

标签: ruby web-services soap wsdl savon

第一次使用SOAP客户端,所以不确定我在这里做错了什么。

以下是我尝试使用的SOAP API:http://services.carsolize.com/BookingServices/DynamicDataService.svc?wsdl

irb(main):018:0> client = Savon.client(wsdl: "http://services.carsolize.com/BookingServices/DynamicDataService.svc?wsdl", convert_request_keys_to: :camelcase)

无论我在call上传递给client,它都会告诉我:

irb(main):022:0> client.call :service_request, :message => {}
HTTPI GET request to services.carsolize.com (net_http)
Savon::UnknownOperationError: Unable to find SOAP operation: :service_request
Operations provided by your service: []
    from /var/lib/gems/1.9.1/gems/savon-2.2.0/lib/savon/operation.rb:22:in `ensure_exists!'
    from /var/lib/gems/1.9.1/gems/savon-2.2.0/lib/savon/operation.rb:14:in `create'
    from /var/lib/gems/1.9.1/gems/savon-2.2.0/lib/savon/client.rb:32:in `operation'
    from /var/lib/gems/1.9.1/gems/savon-2.2.0/lib/savon/client.rb:36:in `call'
    from (irb):22
    from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
    from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
    from /var/lib/gems/1.9.1/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

我知道SOAP服务没有报告任何操作。有没有办法解决?在我身边有什么东西搞砸了,还是网络服务?

Savon版本:2.2.0

1 个答案:

答案 0 :(得分:4)

Savon 2.x.x可以在没有WSDL的情况下访问Web服务。 我检查了您使用SoapUI提供的WSDL,并使用输出创建了以下代码剪切。

它不起作用,因为我显然没有正确的凭据,但它应该让你知道在哪里继续。

#!ruby
#
gem 'savon', '~> 2.0'
require 'savon'

client = Savon.client(
    endpoint: 'http://services.carsolize.com/BookingServices/DynamicDataService.svc',
    soap_action: "http://tempuri.org/IDynamicDataService/ServiceRequest",
    namespace: 'http://tempuri.org/',
    convert_request_keys_to: :camelcase,
    env_namespace: :soapenv,
    namespace_identifier: :tem,
    log: true,
    log_level: :debug,
    pretty_print_xml: true
)

response = client.call(:service_request,
                       message: {
                          'tem:rqst' => {
                            'BookAsUser' => 'nobody',
                            'Credentials' => {
                              'Password' => 'super secret',
                              'UserName' => 'JoeSixpack'
                            },
                            'Request' => {
                              'ClientIP' => '192.168.142.857'
                            },
                            'RequestType' => 'reservation',
                            'SessionID' => 'AAAAAAAAAAAAAABBBBBBBBBBBBB',
                            'TypeOfService' => 'speedy'
                          }
                       }
                      )
 p response.to_hash