0

在我的 Rails(3.1) 应用程序中实现 SOAP 服务时,wash_out (0.9.0) 非常有帮助。我面临的一个小问题是,对于 SOAP 正文中的 XML 有效负载, < >正在被替换为 &lt; &gt;

这是我的代码片段

render :soap => "<person><firstname>larry</firstname></person>"

输出是

<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://www.w3.org/2001/12/soap-envelope"> <soap:Body> <tns:index_response> <value xsi:type="xsd:string">&lt;person&gt;&lt;firstname&gt;larry&lt;/firstname&gt;&lt;/person&gt;</value> </tns:index_response> </soap:Body> </soap:Envelope>

这是一个错误还是我可以通过一些配置或附加代码来解决这个问题。请帮忙。

4

2 回答 2

1

试试这个(没有测试):

render :soap => "<person><firstname>larry</firstname></person>".html_safe
于 2014-10-15T18:02:06.193 回答
0

我能够解决这个问题。我做错了一件事。

我正在使用savon客户端来调用我的 SOAP 服务。我在做
client = Savon::Client.new(wsdl: "")
result = client.call(...)
puts result

这是显示&lt;&gt;

在我的情况下访问响应内容的正确方法是
result.body[:index_response][:value]
result.body返回一个哈希

有了 Nokogiri 我可以做到doc = Nokogiri::XML(result.body.to_xml)

这适用于有效负载中的 XML。

于 2014-10-16T21:11:12.627 回答