Using SOAP and other Standard Libraries in Ruby 1.9.2

半腔热情 提交于 2019-12-18 12:02:53

问题


So, I recently upgraded to 1.9.2 Ruby, having used 1.8.7 for forever (I wanted to try out Rails 3).

The BIGGEST problem I'm having is that none of my SOAP require statements are working...I have things like:

 require 'soap/rpc/driver'
 require 'xsd/qname'
 require 'soap/wsdlDriver'
 require 'ftools'

Even ftools isn't working, but I THINK (look at the Ruby source) that this became 'fileutils'? But I don't see anything similar for SOAP.....has it just been removed?

If so...what should I do? Is there any plug ins that do essentially the same thing?

My code is like:

 require 'soap/wsdlDriver'
     def send_package
     adi_url = "ftp://anonymous:ads123@#{APP_CONFIG['pcms_ip']}/#{self.id}/original/ADI.XML" 


     cl0 = SOAP::WSDLDriverFactory.new(APP_CONFIG['corba_bridge'])
     driver = cl0.create_rpc_driver
     driver.streamhandler.client.receive_timeout = 10
     x = driver.exportPackage2(self.name+self.id.to_s, adi_url, "NS2.PackageFactory")
     log x

     if x.to_s =~ /ERROR/
          raise x.to_s
     end
 end

and

 require 'soap/rpc/driver'
 require 'xsd/qname'
 def get_self_offering_ids(wsdl, namespace)
      ret = []
      input = {"#{namespace}:includeAssetMetadata" => 'true'}

      begin
           driver = SOAP::RPC::Driver.new(wsdl, namespace)
           driver.add_document_method('GetAllOfferingsRequest', "OpenStreamVOD#getAllOfferings", XSD::QName.new(namespace, "GetAllOfferingsRequest"), XSD::QName.new(namespace, "GetAllOfferingsResponse"))
           result = driver.GetAllOfferingsRequest(input)
      rescue => err
               log err                        
      end

      if result
           result.offering.each do |o|
                if offeringIsSelf?(o)
                   ret << o.xmlattr_offeringId
                end
           end 
      end

      return ret
 end

I don't have much soap experience...and I'm not even sure how wsdlDriver and rpc/driver are any different...just that I probably had a good reason for using the two separate libraries at the time?


回答1:


If you want to keep using Ruby 1.8's standard soap library (aka soap4r), you can try https://github.com/spox/soap4r-spox ...

wget --no-check-certificate https://github.com/spox/soap4r-spox/tarball/1.5.8.4
tar -xzf spox-soap4r-spox-1.5.8.4-0-g345a6cb.tar.gz
cd spox-soap4r-spox-345a6cb/
ruby setup.rb all

If you're using rvm, don't sudo the last command... instead su into root and rvm to ruby 1.9 so that setup.rb puts the files into the right place.

$ irb
ruby-1.9.2-p0 > require 'soap/rpc/driver'
 => true 
ruby-1.9.2-p0 > require 'xsd/qname'
 => false 
ruby-1.9.2-p0 > require 'soap/wsdlDriver'
 => true 
ruby-1.9.2-p0 > require 'fileutils'
 => true 

As suggested by other StackOverflow answers, you might want to switch to a gem like savon.




回答2:


https://rubygems.org/gems/soap4r-ruby1.9

gem install soap4r-ruby1.9

This gem solved most of my soap related issues with ruby 1.9




回答3:


if you are trying rails 3 update your gem file with

gem 'soap4r', :git => 'git://github.com/felipec/soap4r.git'

this is updated with fix.



来源:https://stackoverflow.com/questions/4878388/using-soap-and-other-standard-libraries-in-ruby-1-9-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!