因此,我传递给Savon client.call的XML请求字符串如下所示(注意,这是可行的,我得到了一个响应):
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/"
xmlns:mun="http://schemas.datacontract.org/2004/07/External.Service.Bo">
<soap:Header/>
<soap:Body>
<tem:GetInformationsForCoordinates>
<tem:coordReq>
<mun:Coordinates>
<mun:Coordinate>
<mun:Id>1</mun:Id>
<mun:QualityIndex>90</mun:QualityIndex>
<mun:X>-110.5322</mun:X>
<mun:Y>35.2108</mun:Y>
</mun:Coordinate>
</mun:Coordinates>
</tem:coordReq>
<tem:analysisTypes>
<mun:AnalysisType>Additional</mun:AnalysisType>
</tem:analysisTypes>
</tem:GetInformationsForCoordinates>
</soap:Body>
</soap:Envelope>我想传递一条消息,这样我就可以轻松地添加多个(可能是一个协作数组)、多个分析类型等等,而不是以xml的形式传递它。
到目前为止,我必须做的Ruby代码是:
coordinate = { Id: '1', QualityIndex: 90, X: -110.5322, Y: 35.2108}
coordinates = {Coordinates: [coordinate] }
coordinateReq = {coordReq: {coordinates: coordinates} }然后我将coordinateReq传递给client.call -我可以在Ruby中看到下面生成的请求:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/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>
<QualityIndex>90</QualityIndex>
<X>-110.5322</X>
<Y>35.2108</Y>
</Coordinates>
</coordinates>
</coordReq>
</tns:GetInformationsForCoordinates>
</env:Body>
</env:Envelope>有几个问题--我是否可以将名称管理单元添加到与XML字符串类似的正确属性(例如Id/QualityIndex,等等)。另外,在我的例子中,Ruby代码的坐标是小写的,然后坐标是大写的,而它应该是大写的,而不是复数的。最后,我需要包含analysisTypes (注意小写,大写T),然后包含AnalysisType off,请求可以是多个,AnalysisType也需要mun命名空间。
发布于 2014-03-27 18:13:28
而不是像这样的符号
QualityIndex: 90您需要指定一个字符串,如
'mun:QualityIndex' => 90发布于 2014-03-28 10:56:10
正如我在评论中提到的那样,使用Steffen shown按预期工作,我确实必须添加名称空间,如下所示(以防其他人遇到这个问题:
namespaces = {
"xmlns:mun" => "http://schemas.datacontract.org/2004/07/External.Service.Bo"
}然后在Savon.client中进行以下操作(注意,关键是名称空间行):
client = Savon.client(wsdl: WSDL_URL,
log: true, # set to true to switch on logging
namespaces: namespaces,
#etc more config set uphttps://stackoverflow.com/questions/22692211
复制相似问题