How to Stop Savon from Adding Prefixes to Soap.Body

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



Leave a reply



Submit