如何阻止Savon向soap.body添加前缀

发布于 2024-11-25 01:30:50 字数 688 浏览 1 评论 0原文

这就是我创建客户端的方式:

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

这就是我获得响应的方式:

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

但是,这会生成以下 xml:

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

由于前缀,我的肥皂服务出现错误。如果我这样做,它会起作用:

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

然而,由于各种原因,这很痛苦。有没有办法阻止 savon 附加前缀?

使用 savon 0.9.6。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

定格我的天空 2024-12-02 01:30:50

这看起来可能是 savon 0.9.6 中的错误。尝试更新您的客户端,创建如下代码:

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

编辑:如果其他人遇到此问题,则使用解决方案更新答案

事实证明,如果您提供 wsdl.document savon 将为您的元素添加前缀。您最好不要使用 wsdl 文档,而只定义您需要的名称空间,如下所示:

@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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文