Вопрос

I had this code in Savon v1:

client = Savon.client("http://www.server.com:9191/soapserver?wsdl")
service = client.request :get_authentication do
  client.http.headers["username"] = "myuser"
  client.http.headers["password"] = "mypass"
end

After the update to savon v2.3.0, I don't manage to retranslate. It should be something like

client = Savon.client do
  wsdl "http://www.shab.ch:9191/soapserver?wsdl
end
service = client.call(:get_authentication, {username: "myuser", password: "mypass"})`

but the line service = client.call(..." does not work. Any idea?

Это было полезно?

Решение

I think what you want to do is:

gem "savon"
require "savon", "~>2.0"
...
client = Savon.client(headers: { username: "user", password: "password"},
                      wsdl: "http://www.example.com/?wsdl",
                      log: true,
                      log_level: :debug,
                      pretty_print_xml: true
                      #, and more options here if necessary)

That will inject the key/values pairs into the http headers.

Другие советы

That last code block of yours is missing a " on line #2 and has a ``` too much in the end. It should look like:

client = Savon.client do
  wsdl "http://www.shab.ch:9191/soapserver?wsdl"
end
service = client.call(:get_authentication, {username: "myuser", password: "mypass"})

to not trigger any syntax errors.

This works for me after a lot of trial and error:

client = Savon.client( wsdl: "http://www.server.com:9191/soapserver?wsdl", <\br>
                       headers: {'username' => 'myuser', 'password' => 'mypass'} )
service = client.call(:get_authentication)

So the header injection I do before calling the :get_authentication function.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top