Ruby & Savon SOAP client - Unable to find SOAP operation

廉价感情. 提交于 2020-01-03 00:22:09

问题


First time working with a SOAP client, so not sure what I'm doing wrong here.

Here's the SOAP API I'm trying to use: 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)

No matter what I pass to call on client, it tells me:

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

I understand that the SOAP service isn't reporting any operations. Is there any way around this? Is it something on my side that's messing it up, or is it the web service?

Savon version: 2.2.0


回答1:


Savon 2.x.x can access a Web Service without a WSDL. I inspected the WSDL you provided with SoapUI and used the output to create the following code snipped.

It doesn't work because I obviously haven't the correct credentials but it should give you the idea where to continue.

#!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


来源:https://stackoverflow.com/questions/18422639/ruby-savon-soap-client-unable-to-find-soap-operation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!