2

Hi I'm using Savon to access some web services.

I'm using this code:

client=Savon.client(
    wsdl: "WebService.wsdl",
    env_namespace: "S",
    convert_request_keys_to: :camelcase
)

response=client.call(:send_doc)  do
    message(
      Attr1: "123",
      Attr2: "ABC")
    )

How do I get the request text sent to server?

Regards Fak

Fakada
  • 563
  • 9
  • 20

2 Answers2

3

Savon 2 provides an Observer interface. You can register an Observer which is notified before the request is send. The interface contains a Builder object where you find the XML content of the request. Builder#pretty() formats the XML content.

class Observer
  def notify(_, builder, _, _)
    puts builder.pretty
    nil
  end
end

Savon.observers << Observer.new

Alternativly you can add log: true to your client configuration. It enables the logging of the requests.

client = Savon.client(log: true, ...)
sschmeck
  • 7,233
  • 4
  • 40
  • 67
1

This isn't possible with stable versions of Savon. However, you can get the request using version 3 of Savon (see the Savon website for installation instructions and more detail). Example from the site:

client = Savon.new('http://example.com?wsdl')
operation = client.operation(service_name, port_name, operation_name)
operation.build # returns SOAP request

You could also monkeypatch Savon methods or set up a custom debugger to get this information with your current Savon version. See these StackOverflow answers for more information:

Community
  • 1
  • 1
Jacob Brown
  • 7,221
  • 4
  • 30
  • 50