我有Savon在Sinatra ruby应用程序中工作。应用程序将被频繁调用,我不想过多地依赖服务器。
在我看来,每次/ test_savon GET命中时,我都会去服务器并再次询问wdsl。我只想做一次,看起来似乎。
我应该将一些客户端作为ruby全局(每个wsdl一个)并重复使用它们吗?
以下是我的代码:NTLM auth - 与MS DynamicsNav服务器通信
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
答案 0 :(得分: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