Search code examples
ruby-on-railssoapsavon

Passing an attribute to a SOAP request using Savon


I'm consuming a simple SOAP web service to get a small piece of HTML to be included in a Rails site. Unfortunately, I'm not particularly familiar with SOAP.

I need to call the TopHtml() SOAP method on the endpoint below but I need to also pass an ID number like TopHtml(29).

I'm using the Savon gem and my code looks a little something like:

response = Savon::Client.new('http://www.xxxxxx.xxx/webservices/services.asmx?wsdl').top_html(29)

which works but returns the default response for when an ID number was not provided.

It seems that the ID number is not being passed. Does anyone know how to pass parameters to Savon SOAP requests?

Many thanks, Tristan


Solution

  • In the interests of time, I ended up preparing the request XML myself which is less than ideal (and almost defeats the purpose of using Savon) but it's the only way I could have the request prepared properly. The XML was provided by the developers of the service.

    client = Savon::Client.new 'http://www.xxxxxx.xxx/webservices/services.asmx?wsdl'
    
    response = client.top_html do |soap|
        soap.xml = ...long xml here...
    end
    

    Yuck but I'm not going to spend anymore time on it.