Skip to content

Instantly share code, notes, and snippets.

@speedmax
Created April 13, 2010 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save speedmax/9cc616c94f366c599df0 to your computer and use it in GitHub Desktop.
Save speedmax/9cc616c94f366c599df0 to your computer and use it in GitHub Desktop.
shameful hack to add default namespace to handsoap
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
@speedmax
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment