1

第一次使用 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)

无论我传递什么callclient它都会告诉我:

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 服务未报告任何操作。有没有办法解决?是我这边搞砸了,还是网络服务?

萨文版本:2.2.0

4

1 回答 1

4

Savon 2.xx 可以在没有 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
于 2013-08-28T02:48:25.910 回答