1

I have Savon working in a Sinatra ruby application. The application will be called frequently, and I don't want to lean on the server too much.

It looks to me that everytime the /test_savon GET is hit, I am going to the server and asking for the wdsl again. I would only need to do that once, it would seem.

Should I make a few clients as ruby globals (one for each wsdl) and use them repeatedly?

Here is my code which works: NTLM auth - talking 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
ian
  • 12,003
  • 9
  • 51
  • 107
Tom Andersen
  • 7,132
  • 3
  • 38
  • 55

1 Answers1

1

I usually don't use a WSDL at all but work without it. That should be much faster because you should have less roundtrips. A small example:

#!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
Steffen Roller
  • 3,464
  • 25
  • 43