你可以猴子patch_out 0.5.2。把這個config/initializers/washout_monkey_patch.rb
WashOut::Param.class_eval do
attr_accessor :optional
def initialize(name, type, multiplied = false, optional = false)
type ||= {}
@name = name.to_s
@raw_name = name.to_s
@map = {}
@multiplied = multiplied
@optional = optional
if WashOut::Engine.camelize_wsdl.to_s == 'lower'
@name = @name.camelize(:lower)
elsif WashOut::Engine.camelize_wsdl
@name = @name.camelize
end
if type.is_a?(Symbol)
@type = type.to_s
elsif type.is_a?(Class)
@type = 'struct'
@map = self.class.parse_def(type.wash_out_param_map)
@source_class = type
else
@type = 'struct'
@map = self.class.parse_def(type)
end
end
def flat_copy
copy = self.class.new(@name, @type.to_sym, @multiplied, @optional)
copy.raw_name = raw_name
copy
end
end
WashOutHelper.module_eval do
def wsdl_occurence(param, inject, extend_with = {})
if param.multiplied
data = {
"#{'xsi:' if inject}minOccurs" => 0,
"#{'xsi:' if inject}maxOccurs" => 'unbounded'
}
elsif param.optional
data = {
"#{'xsi:' if inject}minOccurs" => 0,
}
else
data = {}
end
extend_with.merge(data)
end
def wsdl_data(xml, params)
Rails.logger.debug params
params.each do |param|
tag_name = param.name
if !param.struct?
if param.multiplied
param.value = [] unless param.value.is_a?(Array)
param.value.each do |v|
xml.tag! tag_name, v, "xsi:type" => param.namespaced_type
end
elsif param.optional
if !param.value.nil?
xml.tag! tag_name, param.value, "xsi:type" => param.namespaced_type
end
else
xml.tag! tag_name, param.value, "xsi:type" => param.namespaced_type
end
else
if param.multiplied
param.map.each do |p|
xml.tag! tag_name, "xsi:type" => param.namespaced_type do
wsdl_data(xml, p.map)
end
end
elsif param.optional
if !param.map.empty?
xml.tag! tag_name, "xsi:type" => param.namespaced_type do
wsdl_data(xml, param.map)
end
end
else
xml.tag! tag_name, "xsi:type" => param.namespaced_type do
wsdl_data(xml, param.map)
end
end
end
end
end
end
要定義一個可選參數,使用沖洗::帕拉姆構造函數,傳遞一個第三個參數等於false
和第四個參數等於true
。在以下示例中,第三個輸入參數和第二個輸出參數將被定義爲可選項:
soap_action "YourWebService",
:args => {
:arg1 => :string,
:arg2 => :string,
:arg3 => WashOut::Param.new(:arg3, :string, false, true),
},
:return => {
:arg1 => :string,
:arg2 => WashOut::Param.new(:arg2, :string, false, true),
},
:to => :web_service
您能澄清一下您的問題嗎?我沒有那麼清楚。看來你正在使用savon。你究竟做了什麼? – Muntasim
我使用香皂作肥皂。我想使用soap API來進行給定的操作是可選的。 – mirfan899
這裏是請求 <肥皂:故障的encodingStyle =」 http://schemas.xmlsoap.org/soap/encoding/ 「> <的faultcode的xsi:type =」 XSD:QName的「>服務器 無法找到 faultstring>的SOAP動作映射 soap:Envelope> –
mirfan899