secret
Last active

shameful hack to add default namespace to handsoap

  • Download Gist
patched_handsoap_service.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
module Handsoap
class Service
def invoke(action, options = { :soap_action => :auto }, &block) # :yields: Handsoap::XmlMason::Element
if action
if options.kind_of? String
options = { :soap_action => options }
end
if options[:soap_action] == :auto
options[:soap_action] = action.gsub(/^.+:/, "")
elsif options[:soap_action] == :none
options[:soap_action] = nil
end
doc = make_envelope do |body,header|
if options[:soap_header]
iterate_hash_array(header, options[:soap_header])
end
if options[:soap_body]
action_hash = { action => options[:soap_body] }
iterate_hash_array(body, action_hash)
else
body.add(action)
end
begin
if default = body.get_namespace('xmlns')
body.set_attr('xmlns', default)
end
rescue
nil
end
end
if block_given?
yield doc.find(action)
end
# ready to dispatch
headers = {
"Content-Type" => "#{self.request_content_type};charset=UTF-8"
}
headers["SOAPAction"] = options[:soap_action] unless options[:soap_action].nil?
on_before_dispatch
request = make_http_request(self.uri, doc.to_s, headers,options[:http_options])
response = http_driver_instance.send_http_request(request)
parse_http_response(response)
end
end
end
end

this operation register with your default namespace

class MyService < Handsoap::Service
  endpoint SERVICE_ENDPOINT

  def on_create_document(doc) 
    doc.alias 'xmlns', 'http://something.com/
  end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.