Mr B
Mr B

Reputation: 4130

Consuming a SOAP service in Ruby using Savon gem

I am trying to consume a SOAP service using the Savon gem but having difficulty. I have accessed the SOAP service using soapUI and it works fine.

My code:

require 'rubygems'
require 'savon'

# Client instance with a WSDL endpoint
client = Savon::Client.new "http://realtime.nationalrail.co.uk/ldbws/wsdl.aspx"

p client.wsdl.namespace_uri

p client.wsdl.soap_actions

response = client.get_arrival_board

The error I am getting:

D, [2010-07-13T11:38:58.967684 #3909] DEBUG -- : Retrieving WSDL from: http://realtime.nationalrail.co.uk/ldbws/wsdl.aspx
"http://thalesgroup.com/RTTI/2008-02-20/ldb/"
[]
/home/abcb293/.gem/ruby/1.8/gems/savon-0.7.9/lib/savon/client.rb:92:in `method_missing': undefined method `get_arrival_board' for #<Savon::Client:0xb7597218> (NoMethodError)
    from natrail.rb:11

Appreciate any help.

Upvotes: 2

Views: 2408

Answers (1)

r3nrut
r3nrut

Reputation: 1055

I don't have all the data you need to pass so I couldn't test this. May very well be an issue with this code but at least it will put you on the right path. Hope it helps.

require 'rubygems'
require 'savon'

wsdl = "http://realtime.nationalrail.co.uk/ldbws/wsdl.aspx"
token = "replace with your data"
numRows = "replace with your data"
crs = "replace with your data"
filterCrs = "replace with your data"
filterType = "replace with your data"
timeOffset = "replace with your data"

# Client instance with a WSDL endpoint
client = Savon::Client.new wsdl
request = client.get_arrival_board { |soap|
soap.namespaces["xmlns:typ"] = "http://thalesgroup.com/RTTI/2010-04-26/ldb/types"
soap.header = {"com:AccessToken" => ["com:TokenValue" => token]}
  soap.body = {
 "typ:GetArrivalBoardRequest" =>[
      "typ:numRows" => numRows,
      "typ:crs" => crs
   "typ:filterCrs" => filterCrs
   "typ:filterType" => filterType
   "typ:timeOffset" => timeOffset]
   }.to_soap_xml
}
puts request

Upvotes: 2

Related Questions