How to stop Savon from adding prefixes to soap.body

亡梦爱人 提交于 2020-01-21 05:32:06

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/6720720/how-to-stop-savon-from-adding-prefixes-to-soap-body

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!