如何阻止Savon向soap.body添加前缀 [英] 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
但是,这会生成以下 xml:
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
然而,由于各种原因,这很痛苦.有没有办法阻止 savon 附加前缀?
However this is a pain for various reasons. Is there a way to stop savon from attaching the prefix?
使用 savon 0.9.6.
Using savon 0.9.6.
推荐答案
这看起来可能是一个 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
事实证明,如果您提供 wsdl.document savon 将为您的元素添加前缀.你最好不要使用 wsdl 文档,而只是像这样定义你需要的命名空间:
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向soap.body添加前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!