wash_out是soap服务的一个很棒的gem,但是无法弄清楚如何在SOAP消息标记上读取或设置属性,如:
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:tns="http://v1.example.com/">
<env:Body>
<SomeTag ID="ABC321" Type="Basic">
Some text here
</SomeTag>
</env:Body>
</env:Envelope>
任何帮助将不胜感激
对wash_out gem的这个小修改允许我为文档样式wsdl呈现标记属性:
def wsdl_data_options(param)
case controller.soap_config.wsdl_style
when 'rpc'
{ :"xsi:type" => param.namespaced_type }
when 'document'
attributes = { }
if param.struct?
if !param.multiplied
param.map.each do |p|
if p.name[0] == '@'
attributes[p.name.gsub('@','')] = p.value
param.map.delete(p)
end
end
end
end
attributes
end
end
现在我的soap_action看起来像这样:
soap_service :wsdl_style => 'document'
soap_action :incoming_request,
:args => {'HotelSearchCriteria' => {'HotelID' => :string}},
:return => {'RoomTypes' => [{'RoomType' => {'@RoomCode' => :string, 'RoomDescription' => {'@Name' => :string, 'Text' => :string}}}]},
:response_tag => 'MyResponse'
def incoming_request
render :soap => {'RoomTypes' => [{'RoomType' => {'@RoomCode' => "#{@room_code}", 'RoomDescription' => {'@Name' => "#{@room_name}", 'Text' => "#{@room_text}"}}}]}
end
呈现以下肥皂信息:
<soap:Body>
<MyResponse>
<RoomTypes>
<RoomType RoomCode="SGL">
<RoomDescription Name="Single Room">
<Text>One King Bedroom</Text>
</RoomDescription>
</RoomType>
</RoomTypes>
</MyResponse>
</soap:Body>
而不是:
<soap:Body>
<MyResponse>
<RoomTypes>
<RoomType>
<RoomCode>SGL</RoomCode>
<RoomDescription>
<Name>Single Room</Name>
<Text>One King Bedroom</Text>
</RoomDescription>
</RoomType>
</RoomTypes>
</MyResponse>
</soap:Body>
@inossidabile 让我知道你的想法