What's the best way to use SOAP with Ruby?

后端 未结 10 1492
别那么骄傲
别那么骄傲 2020-11-27 10:15

A client of mine has asked me to integrate a 3rd party API into their Rails app. The only problem is that the API uses SOAP. Ruby has basically dropped SOAP in favor of RE

相关标签:
10条回答
  • 2020-11-27 10:52

    Kent Sibilev from Datanoise had also ported the Rails ActionWebService library to Rails 2.1 (and above). This allows you to expose your own Ruby-based SOAP services. He even has a scaffold/test mode which allows you to test your services using a browser.

    0 讨论(0)
  • 2020-11-27 10:58

    I was having the same issue, switched to Savon and then just tested it on an open WSDL (I used http://www.webservicex.net/geoipservice.asmx?WSDL) and so far so good!

    https://github.com/savonrb/savon

    0 讨论(0)
  • 2020-11-27 10:59

    We switched from Handsoap to Savon.

    Here is a series of blog posts comparing the two client libraries.

    0 讨论(0)
  • 2020-11-27 11:01

    I have used HTTP call like below to call a SOAP method,

    require 'net/http'
    
    class MyHelper
      def initialize(server, port, username, password)
        @server = server
        @port = port
        @username = username
        @password = password
    
        puts "Initialised My Helper using #{@server}:#{@port} username=#{@username}"
      end
    
    
    
      def post_job(job_name)
    
        puts "Posting job #{job_name} to update order service"
    
        job_xml ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://test.com/Test/CreateUpdateOrders/1.0\">
        <soapenv:Header/>
        <soapenv:Body>
           <ns:CreateTestUpdateOrdersReq>
              <ContractGroup>ITE2</ContractGroup>
              <ProductID>topo</ProductID>
              <PublicationReference>#{job_name}</PublicationReference>
           </ns:CreateTestUpdateOrdersReq>
        </soapenv:Body>
     </soapenv:Envelope>"
    
        @http = Net::HTTP.new(@server, @port)
        puts "server: " + @server  + "port  : " + @port
        request = Net::HTTP::Post.new(('/XISOAPAdapter/MessageServlet?/Test/CreateUpdateOrders/1.0'), initheader = {'Content-Type' => 'text/xml'})
        request.basic_auth(@username, @password)
        request.body = job_xml
        response = @http.request(request)
    
        puts "request was made to server " + @server
    
        validate_response(response, "post_job_to_pega_updateorder job", '200')
    
      end
    
    
    
      private 
    
      def validate_response(response, operation, required_code)
        if response.code != required_code
          raise "#{operation} operation failed. Response was [#{response.inspect} #{response.to_hash.inspect} #{response.body}]"
        end
      end
    end
    
    /*
    test = MyHelper.new("mysvr.test.test.com","8102","myusername","mypassword")
    test.post_job("test_201601281419")
    */
    

    Hope it helps. Cheers.

    0 讨论(0)
提交回复
热议问题