1

我让Savon在 Sinatra ruby​​ 应用程序中工作。应用会被频繁调用,不想过多依赖服务器。

在我看来,每次 /test_savon GET 被击中时,我都会去服务器并再次请求 wdsl。我只需要这样做一次,看起来。

我应该将一些客户端作为 ruby​​ 全局变量(每个 wsdl 一个)并重复使用它们吗?

这是我的有效代码:NTLM auth - talk to a MS DynamicsNav Server

get '/test_savon' do
  # create a client for the service
  client = Savon.client(wsdl: 'http://somedynamicsnavserver:7047/WS/Page/Salesperson', ntlm: ["username", "password"])  do
    convert_request_keys_to :camelcase  
  end
  operations = client.operations
  puts "operations are #{operations.to_s}" if operations
  puts "checked operations" if operations

  # => [:find_user, :list_users]

  # call the 'findUser' operation
  response = client.call(:read, message: { code: 'salepersonIDhere' })
  puts "response is #{response.to_s}" if response

  response.body.to_s
  # => {:read_result=>{:salesperson=>{:key=>"aKey", :code=>"salepersonIDhere", :name=>"Jim Kirk", :global_code=>"X", :phone_no=>"4407"}, :@xmlns=>"urn:microsoft-dynamics-schemas/page/salesperson"}}
end
4

1 回答 1

1

我通常根本不使用 WSDL,但没有它就可以工作。这应该快得多,因为您应该有更少的往返。一个小例子:

#!ruby

gem "savon", "~>2.0"
require 'savon'

stock_handle = ARGV[0] || 'OTEX'

client = Savon.client( 
  endpoint: 'http://www.webservicex.net/stockquote.asmx',
  namespace: 'http://www.webserviceX.NET/',
  convert_request_keys_to: :camelcase, # :camelcase, :upcase, :none
  log: true,
  log_level: :debug,
  pretty_print_xml: true
)

response = client.call(
  :get_quote,
  soap_action: 'http://www.webserviceX.NET/GetQuote',
  message: { "wsdl:symbol" => stock_handle}
)

print response.to_hash
于 2013-11-14T21:27:28.980 回答