How to stop Savon from adding prefixes to soap.body
This looks like it might be a bug in savon 0.9.6. Try updating your client creating code like this:
@client = Savon::Client.new do
wsdl.document = my_document
wsdl.endpoint = my_endpoint
wsdl.element_form_default = :unqualified
end
Edit: updating answer with solution if someone else comes across this issue
It turns out if you provide a wsdl.document savon will prefix your elements. You're better off not using the wsdl document and just defining the namespaces you need like this:
@client = Savon::Client.new do
wsdl.endpoint = "http://..."
wsdl.namespace = "http://..." # target namespace
end
@response = @client.request :namespace_prefix, :soap_action do
soap.element_form_default = :unqualified
soap.namespaces["xmlns:ns1"] = "http://..."
soap.namespaces["xmlns:ns2"] = "http://..."
soap.body = {:application_id => my_application_id }
end
Savon ruby gem adds ins0 to tags
The two XML documents are equivalent, so there should be no issues as long as the document is parsed by an XML compliant agent.
The Savon generated document is simply creating a namespace prefix of ins0 for the "SOME URL" namespace. This is convenient for a large SOAP document with many elements from that namespace. In this example, the prefix is not really necessary.
The only potential issue I can see is that the Savion generated document seems to declare the ins0 namespace twice - once in the soap:Envelope and then again in the soap:Body. Seems superfluous and potentially open to error.
SOAP call in Ruby on Rails using Savon gets weird around the envelope and main operation
Ok this works (verified)
@client = Savon.client(
:wsdl => 'https://testservice.postnl.com/CIF_SB/BarcodeWebService/1_1/?wsdl',
:log => true,
:wsse_auth => ['devc_!R4xc8p9', 'xxx'],
:pretty_print_xml => true,
:convert_request_keys_to => :camelcase,
:env_namespace => :s,
:namespace_identifier => nil
)
message = {
"d6p1:Message" => {
"d6p1:MessageID" => "10",
"d6p1:MessageTimeStamp" => Time.now.strftime("%d-%m-%Y %H:%M:%S")
},
"d6p1:Customer" => {
"d6p1:CustomerCode" => "DEVC",
"d6p1:CustomerNumber" => "11223344"},
"d6p1:Barcode" => {
"d6p1:Type" => "3S",
"d6p1:Range" => "DEVC",
"d6p1:Serie" => "1000000-2000000" }
}
attributes = { "xmlns:d6p1" => "http://postnl.nl/cif/domain/BarcodeWebService/",
"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance",
"xmlns" => "http://postnl.nl/cif/services/BarcodeWebService/"}
@client.call(:generate_barcode, :attributes => attributes,
:message => message,
:soap_header => { "Action" => "http://postnl.nl/cif/services/BarcodeWebService/IBarcodeWebService/GenerateBarcode"})
So the trick was adding :namespace_identifier => nil
and sending attributes
. Setting namespace_identifier removes the wsdl
from GenerateBarcode
ans attributes sets some namespaces on GenerateBarcode
tag. Now I remember why I hate SOAP so much :(
Related Topics
Test (With Rspec) a Controller Outside of a Rails Environment
Scraping a Site That Requires Login Username and Password on Two Separate Pages
Parsing Command-Line Arguments as Wildcards
How to Access a Symbol Hash Key Using a Variable in Ruby
Is There an Elegant Way to Exclude the First Value of a Range
Encoding Issues in JavaScript Files Using Rails Asset Pipeline
Ruby on Rails. Bundler. Cucumber. Rake Aborted! Command Failed with Status (1)
Generating a Race Condition with Mri
Rails: Parameterfilter::Compiled_Filter Tries to Dup Symbol
How to Create a Custom Method for the Rails Console
Rails 3 and PDFkit. How to Specify Page Size
Ruby/Rails Array of Strings to Postgresql Insert
How to Convert 1 to "First", 2 to "Second", and So On, in Ruby
Trouble Installing Ruby 1.9.2 with Rvm MAC Os X
Web Page Scraping Gems/Tools Available in Ruby