Class: Savon::WSDL
Overview
Savon::WSDL
Savon::WSDL represents the WSDL of your service, including information like the namespace URI, the SOAP endpoint and available SOAP actions.
The WSDL document
Retrieve the raw WSDL document:
client.wsdl.to_s
Available SOAP actions
Get an array of available SOAP actions:
client.wsdl.soap_actions
# => [:get_all_users, :get_user_by_id]
Namespace URI
Get the namespace URI:
client.wsdl.namespace_uri
# => "http://ws.userservice.example.com"
SOAP endpoint
Get the SOAP endpoint:
client.wsdl.soap_endpoint
# => "http://example.com"
Disable Savon::WSDL
Especially with large services (i.e. Ebay), getting and parsing the WSDL document can really slow down your request. The WSDL is great for exploring a service, but it’s recommended to disable it for production.
When disabling the WSDL, you need to pay attention to certain differences:
-
You instantiate Savon::Client with the actual SOAP endpoint instead of pointing it to the WSDL of your service.
-
You also need to manually specify the SOAP.namespace.
-
Append an exclamation mark (!) to your SOAP call:
client = Savon::Client.new "http://example.com"
client.get_user_by_id! do |soap|
soap.namespace = "http://example.com/UserService"
soap.body = { :id => 666 }
end
Without the WSDL, Savon also has to guess the name of the SOAP action and input tag. It takes the name of the method called on its client instance, converts it from snake_case to lowerCamelCase and uses the result.
The example above expects a SOAP action with an original name of “getUserById”. If you service uses UpperCamelCase method names, you can just use the original name:
client.GetAllUsers!
For special cases, you could also specify the SOAP.action and SOAP.input inside the block:
client.get_user_by_id! do |soap|
soap.namespace = "http://example.com/UserService"
soap.action = "GetUserById"
soap.input = "GetUserByIdRequest"
soap.body = { :id => 123 }
end
Instance Attribute Summary collapse
-
#enabled ⇒ Object
writeonly
Sets whether to use the WSDL.
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
Returns whether to use the WSDL.
-
#initialize(request, soap_endpoint = nil) ⇒ WSDL
constructor
Expects a Savon::Request and accepts a custom
soap_endpoint
. -
#namespace_uri ⇒ Object
Returns the namespace URI of the WSDL.
-
#operation_from(soap_action) ⇒ Object
Returns an Array containg the SOAP action and input for a given
soap_call
. -
#operations ⇒ Object
Returns a Hash of SOAP operations including their corresponding SOAP actions and inputs.
-
#respond_to?(method) ⇒ Boolean
Returns
true
for available methods and SOAP actions. -
#soap_actions ⇒ Object
Returns an Array of available SOAP actions.
-
#soap_endpoint ⇒ Object
Returns the SOAP endpoint.
-
#soap_endpoint=(endpoint) ⇒ Object
Overrides the wsdl’s endpoint.
-
#to_s ⇒ Object
Returns the raw WSDL document.
Constructor Details
#initialize(request, soap_endpoint = nil) ⇒ WSDL
Expects a Savon::Request and accepts a custom soap_endpoint
.
75 76 77 |
# File 'lib/savon/wsdl.rb', line 75 def initialize(request, soap_endpoint = nil) @request, @enabled, @soap_endpoint = request, true, soap_endpoint end |
Instance Attribute Details
#enabled=(value) ⇒ Object (writeonly)
Sets whether to use the WSDL.
80 81 82 |
# File 'lib/savon/wsdl.rb', line 80 def enabled=(value) @enabled = value end |
Instance Method Details
#enabled? ⇒ Boolean
Returns whether to use the WSDL. Defaults to true
.
83 84 85 |
# File 'lib/savon/wsdl.rb', line 83 def enabled? @enabled end |
#namespace_uri ⇒ Object
Returns the namespace URI of the WSDL.
88 89 90 |
# File 'lib/savon/wsdl.rb', line 88 def namespace_uri @namespace_uri ||= stream.namespace_uri end |
#operation_from(soap_action) ⇒ Object
Returns an Array containg the SOAP action and input for a given soap_call
.
120 121 122 123 |
# File 'lib/savon/wsdl.rb', line 120 def operation_from(soap_action) return [soap_action.to_soap_key, soap_action.to_soap_key] unless enabled? [operations[soap_action][:action], operations[soap_action][:input]] end |
#operations ⇒ Object
Returns a Hash of SOAP operations including their corresponding SOAP actions and inputs.
99 100 101 |
# File 'lib/savon/wsdl.rb', line 99 def operations @operations ||= stream.operations end |
#respond_to?(method) ⇒ Boolean
Returns true
for available methods and SOAP actions.
114 115 116 117 |
# File 'lib/savon/wsdl.rb', line 114 def respond_to?(method) return true if !enabled? || soap_actions.include?(method) super end |
#soap_actions ⇒ Object
Returns an Array of available SOAP actions.
93 94 95 |
# File 'lib/savon/wsdl.rb', line 93 def soap_actions @soap_actions ||= stream.operations.keys end |
#soap_endpoint ⇒ Object
Returns the SOAP endpoint.
104 105 106 |
# File 'lib/savon/wsdl.rb', line 104 def soap_endpoint @soap_endpoint ||= stream.soap_endpoint end |
#soap_endpoint=(endpoint) ⇒ Object
Overrides the wsdl’s endpoint
109 110 111 |
# File 'lib/savon/wsdl.rb', line 109 def soap_endpoint=(endpoint) @soap_endpoint = endpoint.is_a?(URI) ? endpoint : URI(endpoint) end |
#to_s ⇒ Object
Returns the raw WSDL document.
126 127 128 |
# File 'lib/savon/wsdl.rb', line 126 def to_s @document ||= @request.wsdl end |