2

I'm reading railscast #290 that are going with savon version 1. So I tried to replace command for version 2, but I couldn't do it.

http://railscasts.com/episodes/290-soap-with-savon?view=asciicast

I replaced the commands like these.

ver1 client = Savon::Client.new("http://www.webservicex.net/uszip.asmx?WSDL")

ver2 client = Savon::Client.new(wsdl: "http://www.webservicex.net/uszip.asmx?WSDL")

ver1 client.wsdl.soap_actions

ver2 client.operations

ver1 client.request :web, :get_info_by_zip, body: { "USZIP" => "90210" }

ver2 client.call(:get_info_by_zip) # need more

How can I set namespace web and body parameter USZIP and 90210?

ironsand
  • 14,329
  • 17
  • 83
  • 176

1 Answers1

3

try this (www.webservicex.net is not very reliable though):

#!ruby

require 'savon'

WSDL_URL = 'http://www.webservicex.net/uszip.asmx?wsdl'

client = Savon.client(wsdl: WSDL_URL,
                      log: true, # set true to switch on logging
                      log_level: :debug,
                      pretty_print_xml: true)

zip = ARGV[0] || "10004"

response = client.call(:get_info_by_zip, message: {"USZip"=>zip})

print response
Steffen Roller
  • 3,464
  • 25
  • 43
  • is their a way to get message keys dynamically example 'USZip' like listing operations – aashish Apr 23 '14 at 12:31
  • I'm afraid I don't understand your question. If I'm guessing right then the WSDL is what you want. It gives you the structure of the SOAP call. – Steffen Roller Apr 24 '14 at 00:21
  • using wsdl will get structure with the operations available. Is their a way to list the message options for each operation. – aashish Apr 24 '14 at 07:52
  • yes, SoapUI will give you the correct syntax with all mandatory and optional parameters. It uses the WSDL for that. – Steffen Roller Apr 24 '14 at 12:25
  • Not implemented, you can extend the WSDL parser if you want :-). Currently you'll get the list of operations and that's it. – Steffen Roller Apr 24 '14 at 22:52