Support for XML-RPC (Delphi)
From RemObjects Wiki
This is an Article about RemObjects SDK for Delphi
Feel free to add your notes to this topic below.
One of the RemObjects SDK's big features has always been the ability to add new message and transport types, which has made it very easy to add a new message type to support XML-RPC.
XML-RPC is a Remote Procedure Call specification based on XML, similar to SOAP, but written to be as simple as possible, while still allowing for more complex data structures. As it is simple and easy to use, there are now many implementations for just about any programming language including C, Perl, PHP, Java, Javascript, Python, Delphi and .NET (the latter two are supported by the RemObjects SDK).
XML-RPC is generally used over HTTP and therefore is firewall friendly. When making a request to a remote server that provides an XML-RPC interface, it builds an xml document. An XML-RPC request payload typically looks like:
<methodCall> <methodName>samples.sum</methodName> <params> <param><value><int>5</int></value></param> <param><value><int>3</int></value></param> </params> </methodCall>
It's a simple xml document containing the name of the method together with its parameters, in this case two integers, 5 and 3. The remote server will read this request, handle it (e.g. add the two values together) and then create a response xml document containing the result. The response would look like:
<methodResponse> <params> <param><value><int>8</int></value></param> </params> </methodResponse>
The following types are supported:
- integer
- Boolean
- string
- double
- date/time in the iso8601 format
- base64 encoded streams
- single dimensional arrays containing simple types , arrays or structures
- Structures containing name/value pairs where the value can contain a structure, array or simple type
In addition, a method can also decide to return an exception (fault), when it fails to process the request.
The RemObjects SDK wraps its types in the best fitting XML-RPC type; or else it passes it as a string. The SDK's XML-RPC implementation can be used both for writing XML-RPC clients and for writing XML-RPC servers.
Generally XML-RPC is used for easy Remote Procedure Calls, where the client or server do not want to use the more verbose SOAP, but still use a standard way of communicating.
Support for PHP Client CodeGen
Our XML-RPC implementation includes a Service Builder code generation plug-in that creates .inc files to use from PHP. As XML-RPC doesn't have any metadata like WSDL has for a SOAP service, the declarations for using XML-RPC services have to be provided. To do this manually, the xmlrpcmsg for every call and the xmlrpcval for every parameter would be needed to be added by hand, making it much easier to make mistakes.
The Service Builder plug-in makes it possible to generate a PHP class based on the PHP XML-RPC library from http://phpxmlrpc.sourceforge.net/ containing all the services, types and their methods.
To do this, have the RODL file containing the server methods open in the Service Builder and click the CodeGen | PHP | Xml Rpc Interface menu item. This will generate a simple .inc file that can be included in the php page(s) using require or include.
From the php page you can then easily call the service:
require("SampleLibrary_intf.inc"); $service = new NewService('http://localhost:8099/xmlrpc'); echo "Passing 15, 12 to the remote XML-RPC server. Result: "; echo $service->Sum(15, 12);
Catching server exceptions in a PHP Client
PHP clients using the RemObjects generated PHP .inc files may not properly re-raise custom exceptions raised on the server. Instead they may report the error message. "Application raised an exception class Exception with message 'Didn't receive 200 OK from remote server. (HTTP/1.1 500 Internal Server Error)'"
In this case change the TROIndyHTTPServer.SendExceptionsAs500 to FALSE and your custom exceptions will be properly re-raised on the PHP client.
Calling non-RemObjects SDK XML-RPC servers
XML-RPC does not have metadata describing the service definition like the RODL or the WSDL format provide, so to call an existing XML-RPC server that was not implemented using RemObjects SDK, you would need to manually re-create the method definitions within the server in Service Builder, and then use the CodeGen menu to generate an interface unit for the target language (Delphi, .NET or PHP).
Product: RemObjects SDK
Available Editions: RemObjects SDK for .NET, Delphi, Xcode, Java and JavaScript
Glossary — Architecture — Articles — Features — Library — Samples