Last Updated: February 25, 2016
·
2.172K
· billwatts

Adding attributes to an input tag with Savon

Do you hate making soap requests? Yeah, I do too, but at least Savon eases the pain. Savon, in my opinion, is easily the best gem out there for making soap requests, but there was a hangup that I'd like to share. When trying to contact a wsdl, the wsdl kept returning an error that it was looking for an input tag with a specific attribute. The wsdl was looking for something like this...

<AnAction xmlns="http://apathtosomething.com" />

It took me a few minutes to figure out, but this is the result...

soap_client = Savon.client("http://pathtowsdl.com/a.svc?wsdl")

response = soap_client.request "AnAction" do
  http.headers["soapAction"] = "AnAction"
  soap.input = ["AnAction", {"xmlns" => "http://apathtosomething.com"}]
  soap.body = {
    "SomeAttribute" => "SomeValue"
  }
end

Which would give you something like this...

<env:Envelope>
  <env:Body>
    <AnAction xmlns="http://apathtosomething.com" />
  </env:Body>
</env:Envelope>

There you have it, if you need an attribute on the input tag, you know how to do it.

2 Responses
Add your response

How can apply this to Savon 2.5.1... this this mi code...

request = { :ApiKey=> safetypayapikey,
:RequestDateTime=> requestdate,
:Language => language,
}
response = client.call( :create
service,
:message => request).body[:customtransactionresponse]

I need add to "Language" node the namespace: xmlns="urn:safetypay:messages:mws:api"

Regards,

over 1 year ago ·

To SAVON 2.51. I need this:

<Language xmlns="urn:safetypay:schema:mws:api">ES</Language>

In Ruby:

:Language => {
:@xmlns => "urn:safetypay:schema:mws:api",
:content! => language
},

Some suggestion?

over 1 year ago ·