XML-RPC
COM client implementations
This is written in VB and has no external dependencies, except that the vbXmlRpc depends on the vbXml library.
The API is 'message based' - you construct the request message and then handle the response message. Here's an example of contructing the request:
Dim linsRequest As New XMLRPCRequest
linsRequest.HostName = "www.oreillynet.com"
linsRequest.HostPort = 80
linsRequest.HostURI = "/meerkat/xml-rpc/server.php"
linsRequest.MethodName = "meerkat.getChannelsByCategory"
linsRequest.Params.AddInteger (List1.ItemData(List1.ListIndex))
Here's the basic send-request / handle-response code:
Dim linsResponse As XMLRPCResponse
Set linsResponse = linsRequest.Submit
If linsResponse.Status <> XMLRPC_PARAMSRETURNED Then
BugOut "Unexpected response from XML-RPC request " & linsResponse.Status
ElseIf linsResponse.Params.Count <> 1 Then
BugOut "Unexpected response from XML-RPC request " & linsResponse.Params.Count & _
" return parameters, expecting 1"
ElseIf linsResponse.Params(1).ValueType <> XMLRPC_ARRAY Then
BugOut "Unexpected response from XML-RPC request " _
& linsUtility.GetXMLRPCType(linsResponse.Params(1).ValueType) _
& " returned, expecting an array"
End If
And here's an example of extracting data from the response :
Dim linsValue As XMLRPCValue
Dim linsMember As XMLRPCMember
For Each linsValue In linsResponse.Params(1).ArrayValue
If linsValue.ValueType <> XMLRPC_STRUCT Then
BugOut "Unexpected response from XML-RPC request " _
& linsUtility.GetXMLRPCType(linsResponse.Params(1).ValueType) _
& " returned, expecting a struct"
End If
For Each linsMember In linsValue.StructValue
If linsMember.Name = "id" Then
llngChanId = linsMember.Value.IntegerValue
ElseIf linsMember.Name = "title" Then
lstrChanTitle = linsMember.Value.StringValue
End If
Next linsMember
List2.AddItem lstrChanTitle
List2.ItemData(List2.ListCount - 1) = llngChanId
Next linsValue
Both the vbxml.dll and vbxmlrpc.dll are well documented with .chm files. Both projects built clean in VB6, and the code itself is well written. Performance seems to be OK - the meerkat example (portions of which are shown above) was very responsive over a dialup connection.
Here's the only documentation, from the home page:
Examples
Calls "someClass.sum" in server localhost, port 80, path /RPC2 with '3' and '5' as arguments
dim xmlrpcserver as comxmlrpc.rpcClient
dim params() as Variant
dim x as Integer
set xmlrpcserver = new comxmlrpc.rpcClient
redim params(1)
params(0) = 3
params(1) = 5
xmlrpcserver.uri = "http://localhost:80/RPC2"
x = xmlrpcserver.execute("someClass.sum",params)
Calls "someClass.structRecv" with a struct as parameter
dim xmlrpcserver as comxmlrpc.rpcClient
dim params() as Variant
dim x as Integer
set xmlrpcserver = new comxmlrpc.rpcClient
dim dictionary As Object
Set dictionary = CreateObject("Scripting.Dictionary")
dictionary.Add "name", "ignacio"
dictionary.Add "age", "17"
redim params(0)
set params(0) = dictionary
xmlrpcserver.uri = "http://localhost:80/RPC2"
x = xmlrpcserver("someClass.structRecv",params) ' using .execute default method
This has numerous bugs, to the point of unusability. On the other hand it's only a couple hundred lines of code (uses MSXML4 and the
base64 encoding library by Alvaro Redondo), so fixing it shouldn't be a huge chore.
--
DaleBrayden - 25 Jun 2003