savon ruby最佳实践-全局客户端还是每个请求一个?
我在Sinatra ruby应用程序中工作。应用程序将被频繁调用,我不想过分依赖服务器 在我看来,每次点击/test_savon GET时,我都会去服务器上再次请求wdsl。看来我只需要做一次 我是否应该将一些客户机作为ruby全局对象(每个wsdl一个)并重复使用它们 下面是我的代码:NTLM auth-与MS DynamicsNav服务器对话savon ruby最佳实践-全局客户端还是每个请求一个?,ruby,sinatra,ntlm,savon,dynamics-nav,Ruby,Sinatra,Ntlm,Savon,Dynamics Nav,我在Sinatra ruby应用程序中工作。应用程序将被频繁调用,我不想过分依赖服务器 在我看来,每次点击/test_savon GET时,我都会去服务器上再次请求wdsl。看来我只需要做一次 我是否应该将一些客户机作为ruby全局对象(每个wsdl一个)并重复使用它们 下面是我的代码:NTLM auth-与MS DynamicsNav服务器对话 get '/test_savon' do # create a client for the service client = Savon.c
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
我通常根本不使用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
我通常根本不使用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
您可以将WSDL缓存在某个位置,然后从文件系统中读取。您可以将WSDL缓存在某个位置,然后从文件系统中读取。感谢您提供的信息。我可能需要做一些类似的事情。谢谢你的信息。我可能不得不做这样的事情。