Ruby Web Service Application - SOAP4R
What is SOAP?
Simple Object Access Protocol (SOAP) is a convention detail for trading information.
SOAP is a straightforward XML-based convention that empowers applications to trade data over HTTP.
Simple Object Access Protocol is a convention detail for trading information. It is a lightweight, basic convention dependent on XML (a subset of the standard all inclusive markup language) intended to be traded on the WEB. Organized and cemented data.
SOAP4R was created by Hiroshi Nakamura for Ruby SOAP applications.
SOAP4R Download: http://raa.ruby-lang.org/venture/soap4r/.
Note: Your part may as of now be introduced in your ruby environment.
You can likewise utilize pearl to introduce this segment in Linux condition. The order is as follows:
If you are creating in a window situation, you should download the zip document and introduce it by executing install.rb.
SOAP4R bolsters two diverse administration types:
- In view of CGI/FastCGI administration (SOAP::RPC::CGIStub)
- Independent administration (SOAP::RPC:StandaloneServer)
This instructional exercise will tell you the best way to set up an independent SOAP administration. The means are as follows:
Step 1 - Inherit SOAP::RPC::StandaloneServer
To actualize your very own independent server, you have to compose another class that is a subclass of SOAP::RPC::StandaloneServer:
Note: If you are composing a FastCGI-based server, you have to acquire the SOAP::RPC::CGIStub class, and the remainder of the program will stay unaltered.
Step 2 - Define the preparing method
Next we characterize the Web Service technique, as we characterize two strategies, one is the expansion of two numbers, one is the division of two numbers:
Step 3 - Announce processing method
Next add the methods we defined on the server, the initialize method is public, for external connections:
The following is a description of each parameter:
|receiver||The object of the method containing the method name. If you define a service method in the same class, the parameter is self.|
|methodName||The name of the method that called the RPC request.|
|paramArg||Parameter Name and Parameter Mode|
In order to understand the inout and out parameters, consider the following service methods, you need to enter two parameters: inParam and inoutParam, return three values after the function is completed: retVal, inoutParam, outParam:
The public calling method is as follows:
Step 4 - Turn on the service
Last we finally start the service by instantiating the derived class and calling the start method:
The following is a description of the request parameters:
|ServerName||Service name, you can take your favorite|
|urn:ruby:ServiceName||Here urn:ruby is fixed, but you can get a unique one for your service ServiceName|
|port||web service port|
Next we will create a separate service through the above steps:
After executing the above program, a local service that listens on port 8080 is started and two methods are exposed: add and div.
You can perform the above services in the background:
$ ruby MyServer.< /span>rb &
Use the SOAP::RPC::Driver class in ruby to develop a SOAP client. Next, let's take a closer look at the use of the SOAP::RPC::Driver class.
The following information is required to invoke the SOAP service:
- SOAP Service URL Address (SOAP Endpoint URL)
- Method Namespace URI
- Service method name and parameter information
Next we will create a SOAP client step by step to call the above SOAP method: add, div:
First Step - Create a SOAP Driver Instance
We can call its new method by instantiating the SOAP::RPC::Driver class as follows:
SOAP::RPC< /span>::Driver.new(endPoint, nameSpace,soapAction)Above we are just a brief introduction to Ruby's Web Service. If you want to know more, you can check out the official documentation: Ruby's Web Service