【发布时间】:2014-03-24 10:34:56
【问题描述】:
我正在尝试从 Ruby on Rails 访问 SOAP 服务 - 从 SOAP UI 我可以很好地访问它,请求 XML 如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:mun="http://schemas.datacontract.org/2004/07/MyExternalService.Map" xmlns:mun1="http://schemas.datacontract.org/2004/07/MyExternalService.Common.Map">
<soapenv:Header/>
<soapenv:Body>
<tem:GetInformationsForCoordinates>
<!--Optional:-->
<tem:coordReq>
<!--Optional:-->
<mun:Coordinates>
<!--Zero or more repetitions:-->
<mun:Coordinate>
<!--Optional:-->
<mun:Id>1</mun:Id>
<!--Optional:-->
<mun:QualityIndex>90</mun:QualityIndex>
<!--Optional:-->
<mun:X>-110.5322</mun:X>
<!--Optional:-->
<mun:Y>35.2108</mun:Y>
</mun:Coordinate>
</mun:Coordinates>
</tem:coordReq>
<!--Optional:-->
<tem:analysisTypes>
<!--Zero or more repetitions:-->
<mun:AnalysisType>Additional</mun:AnalysisType>
</tem:analysisTypes>
</tem:GetInformationsForCoordinates>
</soapenv:Body>
</soapenv:Envelope>
如果我将确切的 XML 复制到带有 request = %q(XML STRING) 的 Ruby 字符串到 savon 中并使用该方法,然后在 Savon 中调用以下内容:
response = client.call(:get_info, xml: request)
它按预期工作,我得到了回应 - 但实际上我只想将参数传递给 Savon。到目前为止,我已经尝试了以下方法:
coordinate = { Id: '1', X: -110.5322, Y: 35.2108, QualityIndex: 90 }
coordinates = {Coordinates: [coordinate] }
coordinateReq = {coordReq: {coordinates: coordinates} }
response = client.call(:get_informations_for_coordinates, message: coordinateReq)
这失败了,如果我查看我发送的 XML,它如下所示:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<tns:GetInformationsForCoordinates>
<coordReq>
<coordinates>
<coordinates>
<Id>1</Id>
<X>-110.5322</X>
<Y>35.2108</Y>
<QualityIndex>90</QualityIndex>
</coordinates>
</coordinates>
</coordReq>
</tns:GetInformationsForCoordinates>
</env:Body>
</env:Envelope>
与从 SOAP UI 发送的内容相比,我缺少 xmlns:mum 命名空间 - 无论如何我可以将它添加到我的请求中,以便将其添加到每个参数,即 X、Y QualityIndex - 也是类似的 tem我的 Savon 调用中的 tns 添加到 SOAPUI 中的 coordReq 但不在我的 Savon 调用中 - 无论如何我可以添加它吗?
我在确定如何构建我的请求的 analysisTypes 和 AnalysisType 部分时也遇到了一些困难?
【问题讨论】:
标签: ruby-on-rails ruby soap savon