2013-02-04 30 views
0

我有一個使用washout創建的SOAP web服務,它有一個參數類型爲base64Binary(我認爲它等同於C#中的byte []]的參數。Ruby SOAP數據類型base64Binary錯誤

我送下列變量來我的web服務參數:

file_data = Base64.encode64(File.binread("/path/to/my/file")) 

它回來與錯誤:

RuntimeError (Invalid WashOut simple type: base64Binary) 

我不是從我的文件路徑正確創建的數據類型?

這裏是Web服務的控制器:

class ServiceController < ApplicationController 
    include WashOut::SOAP 

    soap_action "import_file", 
       :args => { :data => :base64Binary, :name => :string}, 
       :return => :string 
    def import_file 
    render :soap => ("response") 
    end 

    # You can use all Rails features like filtering, too. A SOAP controller 
    # is just like a normal controller with a special routing. 
    before_filter :dump_parameters 
    def dump_parameters 
    Rails.logger.debug params.inspect 
    end 
end 

這裏是我的客戶代碼:

require 'savon' 

class ServiceTester 
    def self.initiate 
    # create a client for your SOAP service 
    client = Savon.client do 
     wsdl "http://localhost:3000/service/wsdl" 
    end 

    file_data = Base64.encode64(File.binread("/path/to/my/file")) 

    response = client.call(:import_file, message: { data: file_data, name: "myfilename" }) 
    end 
end 

回答

1

你從哪兒弄來:base64Binary? WSDL參數沒有這種類型:

operation = case type 
    when 'string'; :to_s 
    when 'integer'; :to_i 
    when 'double'; :to_f 
    when 'boolean'; nil 
    when 'date';  :to_date 
    when 'datetime'; :to_datetime 
    when 'time';  :to_time 
    else raise RuntimeError, "Invalid WashOut simple type: #{type}" 
end 

嘗試:string來代替。

+0

請原諒我的無知,我碰巧碰到base64Binary的時候用肥皂字節數組。字符串工作正常,謝謝,我想我需要不同的數據類型來表示像.NET一樣的字節數組使用byte []。但是根據你的回答,假設.NET中的byte []只是最終被轉換爲字符串,並且一旦發出請求就可能是安全的。 – James