Professional Documents
Culture Documents
Path: vendor/rails/actionwebservice/README
Last Update: Fri Mar 10 04:58:47 GMT 2006
Features
SOAP RPC protocol support
Dynamic WSDL generation for APIs
XML-RPC protocol support
Clients that use the same API definitions as the server for easy
interoperability with other Action Web Service based applications
Type signature hints to improve interoperability with static languages
Active Record model class support in signatures
The implementation of the methods is done separately from the API specification.
Action Web Service will camelcase the method names according to Rails Inflector
rules for the API visible to public callers. What this means, for example, is that the
method names in generated WSDL will be camelcased, and callers will have to
supply the camelcased name in their requests for the request to succeed.
If you do not desire this behaviour, you can turn it off with the
ActionWebService::API::Base inflect_names option.
Inflection examples
Disabling inflection
def add
end
def remove
end
end
Direct dispatching
This is the default mode. In this mode, public controller instance methods
implement the API methods, and parameters are passed through to the methods in
accordance with the API specification.
The return value of the method is sent back as the return value to the caller.
In this mode, a special api action is generated in the target controller to unwrap the
protocol request, forward it on to the relevant method and send back the wrapped
return value. This action must not be overridden.
def add
end
def remove
end
end
For this example, protocol requests for Add and Remove methods sent to
/person/api will be routed to the controller methods add and remove.
Delegated dispatching
This mode can be turned on by setting the web_service_dispatching_mode option
in a controller to :delegated.
In this mode, the controller contains one or more web service objects (objects that
implement an ActionWebService::API::Base definition). These web service objects
are each mapped onto one controller action only.
def add
end
def remove
end
end
For this example, all protocol requests for PersonService are sent to the
/api/person action.
The /api/person action is generated when the web_service method is called. This
action must not be overridden.
Other controller actions (actions that aren’t the target of a web_service call) are
ignored for ActionWebService purposes, and can do normal action tasks.
Layered dispatching
This mode can be turned on by setting the web_service_dispatching_mode option
in a controller to :layered.
This mode is similar to delegated mode, in that multiple web service objects can be
attached to one controller, however, all protocol requests are sent to a single
endpoint.
Use this mode when you want to share code between XML-RPC and SOAP clients,
for APIs where the XML-RPC method names have prefixes. An example of such a
method name would be blogger.newPost.
For this example, an XML-RPC call for a method with a name like
mt.getCategories will be sent to the getCategories method on the :mt service.
You can also customize the namespace used in the generated WSDL for custom
types and message definition types:
The default in Ruby is to use US-ASCII encoding for strings, which causes a string
validation check in the Ruby SOAP library to fail and your string to be sent back as
a Base-64 value, which may confuse clients that expected strings because of the
WSDL.
Start Ruby using the -Ku command-line option to the Ruby executable
Set the $KCODE flag in config/environment.rb to the string ‘UTF8‘
Example:
class PersonApiControllerTest < Test::Unit::TestCase
def setup
@controller = PersonController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_add
result = invoke :remove, 1
assert_equal true, result
end
end
This example invokes the API method test, defined on the PersonController, and
returns the result.
Scaffolding
You can also test your APIs with a web browser by attaching scaffolding to the
controller.
Example:
class PersonController
web_service_scaffold :invocation
end
Navigating to this action lets you select the method to invoke, supply the
parameters, and view the result of the invocation.
Note: The client support is intended for communication between Ruby on Rails
applications that both use Action Web Service. It may work with other servers, but
that is not its intended use, and interoperability can’t be guaranteed, especially not
for .NET web services.
Web services protocol specifications are complex, and Action Web Service client
support can only be guaranteed to work with a subset.
Dependencies
Action Web Service requires that the Action Pack and Active Record are either
available to be required immediately or are accessible as GEMs.
It also requires a version of Ruby that includes SOAP support in the standard
library. At least version 1.8.2 final (2004-12-25) of Ruby is recommended; this is
the version tested against.
Download
The latest Action Web Service version can be downloaded from
rubyforge.org/projects/actionservice
Installation
You can install Action Web Service with the following command.
License
Action Web Service is released under the MIT license.
Support
The Ruby on Rails mailing list