我让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