1

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

vic700208
  • 41
  • 6
  • What exactly are you trying to achieve? Normally you shouldn't be going down to XML at all with SOAP. Why do you want to read it? – inossidabile Dec 04 '13 at 06:36
  • @inossidabile Thank You for replying. I'm trying to implement a soap interface to a third-party service that is expecting some of the returned values to be passed as tag attributes. Here is a example: Bedding is Queen sized bed. Continental breakfast for each guest. I can't figure out how to set the values corresponding to RoomCode and RoomName in the above example. – vic700208 Dec 04 '13 at 16:45
  • @inossidabile Made a small modification to the wash_out gem in order to render tag attributes: `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` – vic700208 Dec 04 '13 at 19:46
  • Can you please paste it somewhere like github gists? – inossidabile Dec 04 '13 at 20:10
  • @inossidabile please see my recent edit above – vic700208 Dec 04 '13 at 20:18
  • Okay. I don't see this solving your issue. It will add that into WSDL, yes, but attributes will simply be dropped by dispatcher. Are you saying this works for you? – inossidabile Dec 05 '13 at 05:08
  • @inossidabile yes, it works, although I had to change the naming convention because WSDL does not like element names that start with a special character, but other than that, it works – vic700208 Dec 10 '13 at 18:04
  • @inossidabile and @vic700208 - So what is the status on this? I would also like to have a parameter an element - so e.g. `` – Jesper Grann Laursen Sep 09 '14 at 11:58

0 Answers0