wash_out(0.9.0)对我在Rails(3.1)应用程序中实现SOAP服务非常有帮助。我面临的一个小问题是,对于SOAP主体中的XML有效负载,< >
将被替换为
< >
这是我的代码段
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"><person><firstname>larry</firstname></person></value>
</tns:index_response>
</soap:Body>
</soap:Envelope>
这是一个错误还是我可以通过某些配置或其他代码来解决这个问题。 请帮助。
答案 0 :(得分:1)
试试这个(没有测试过):
render :soap => "<person><firstname>larry</firstname></person>".html_safe
答案 1 :(得分:0)
我能够解决这个问题。有一件事我做错了。
我正在使用savon客户端来调用我的SOAP服务。我在做什么
client = Savon::Client.new(wsdl: "")
result = client.call(...)
puts result
这显示<
和>
在我的案例中访问响应内容的正确方法是
result.body[:index_response][:value]
result.body
返回哈希
借助Nokogiri,我可以做doc = Nokogiri::XML(result.body.to_xml)
这适用于有效负载中的XML。