开发者

How to stop Savon from adding prefixes to soap.body

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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜