3

This is how I am creating a a client:

@client = Savon::Client.new do
  wsdl.document = my_document
  wsdl.endpoint = my_endpoint
end

and this is how I'm getting a response:

@response = @client.request :the_action do
  soap.body = xml
  soap.body = {"applicationId" => my_application_id }
end

However, this generates the following xml:

"<ins5:applicationId>XXXXXXXXXXXXXX</ins5:applicationId>"

My soap service errors out because of the prefix. If I do this instead, it works:

@response = @client.request :the_action do
  soap.body =  "<applicationId>#{my_application_id}</applicationId>"
end

However this is a pain for various reasons. Is there a way to stop savon from attaching the prefix?

Using savon 0.9.6.

David
  • 7,310
  • 6
  • 41
  • 63

1 Answers1

5

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
David
  • 7,310
  • 6
  • 41
  • 63
Dylan Markow
  • 123,080
  • 26
  • 284
  • 201
  • That gives me this error: `NoMethodError: undefined method 'element_form_default=' for # `. I've also tried to put `soap.element_form_default = :unqualified` in the request block but it still appends the prefix. – David Jul 17 '11 at 00:06
  • furthermore, `@client.wsdl.element_form_default` outputs `:unqualified`, which is perplexing. – David Jul 17 '11 at 00:17
  • Digging into the code of Savon, it looks like it will automatically insert these `ins0`, `ins1`, etc. prefixes if you don't have a namespace specified. Can you set a `wsdl.namespace`? – Dylan Markow Jul 17 '11 at 00:27
  • I did, with the same results. :S – David Jul 17 '11 at 01:20
  • 1
    Turns out it will ignore `element_form_default` if you have `wsdl.document` defined. – David Jul 18 '11 at 01:11