wash_out is a great gem for a soap service, but can't figure out how to read or set attributes on the SOAP message tag, as in:
<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>
any help would be much appreciated
This small modification to the wash_out gem allows me to render tag attributes for document style 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
Now my soap_action looks like this:
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
Rendering the following soap message:
<soap:Body>
<MyResponse>
<RoomTypes>
<RoomType RoomCode="SGL">
<RoomDescription Name="Single Room">
<Text>One King Bedroom</Text>
</RoomDescription>
</RoomType>
</RoomTypes>
</MyResponse>
</soap:Body>
Instead of:
<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 Let me know your thougts