2014-01-27 2 views
0

Ryan Bates의 루비 캐스트에서이 코드를 실행 해 보았지만 작동하지 않습니다. Savon 1을 사용한다고 가정합니다.어떻게이 Savon 1 코드를 Savon 2로 변환합니까?

require "savon" 

client = Savon::Client.new("http://www.webservicex.net/uszip.asmx?WSDL") 
response = client.request :web, :get_info_by_zip, body: { "USZip" => zip } 
if response.success? 
    data = response.to_array(:get_info_by_zip_response, :get_info_by_zip_result, :new_data_set, :table).first 
    if data 
    @state = data[:state] 
    @city = data[:city] 
    @area_code = data[:area_code] 
    @time_zone = data[:time_zone] 

    puts @state 
    puts @city 
    puts @area_code 
    end 
end 

Savon 2의 올바른 구현 방법은 무엇입니까? 복사하여 붙이기를 원한다.

답변

0

다음은 SOAP-Services를 다른 루비 객체에 제공하는 Service-Wrapper 클래스에서 발췌 한 것입니다. 각 SOAP 작업에 WSDL 위치와 고유 한 메서드를 제공하여 클라이언트를 초기화합니다. thirdparty 메소드는 @ client.call을 사용하여 제공된 params를 사용하여 SOAP 메시지를 생성하는 블록을 전달하여 호출됩니다.

response = client.call(:get_info_by_zip) do 
    message USZip: zip 
end 
:

class Client 
    include Singleton 

    def wsdl_method_to_call 
     begin 
     response = @client.call(:wsdl_method_to_call) do 
      message auth:CREDENTIALS, param_1: param_1_value, param_2: param_2_value 
     end 
     rescue 
     raise CustomServiceException.new("Error ... , response : #{response}") 
     end 
    end 


    def initialize() 
     @client = Savon::Client.new(wsdl: WSDL) 
    end 

    private 
    WSDL = "http://service_host/wsdl" 
    CREDENTIALS = "foo|bar" 

    end 

어쩌면 당신이 뭔가를 시도해야한다