![]() |
LuaSOAP Reference Manual |
SOAP interface to the Lua programming language |
LuaSOAP is a Lua library to ease the use of SOAP. It enables a Lua program to:
LuaSOAP provides a very simple API and an abstraction layer over XML avoiding manipulation of string representation of data structures.
LuaSOAP is based on LuaExpat and on Lua 5.0.
The abstraction layer over HTTP depends on LuaSocket 2.0.
SOAP elements are always represented by Lua tables except strings. A SOAP element is a table of the form defined by the Lua Object Model from the LuaExpat library. The table has the following characteristics:
tag
with the element's
name;attr
with the
element's attributes (see next section);The special field attr
is a Lua table that stores
the SOAP element's attributes as pairs
<key>=<value>. To assure an order (if
necessary), the sequence of keys should be placed at the
array-part of the table.
The file soap.lua
implements all basic support for
encoding and decoding SOAP messages. There are two functions:
encode (namespace, element_name, entries, headers*)
=> envelope
SOAP-Envelope
element. It receives two strings with the namespace (an URI) and
the SOAP-element's name and, as the third argument, a table with
zero or more SOAP elements. An
optional fourth argument can be used to generate the SOAP Header
(it must be a SOAP element too). The
result is a string containing the SOAP document. decode (method_response) => namespace,
element_name, elements
The file soap.http.lua
implements a simple
stand-alone client based on LuaSocket 2.0. The
following function is provided:
call (url, namespace, element_name, entries,
headers*)
encode
and
decode
over a connection to an HTTP server. The result
is the same as decode function: the namespace
(string), the SOAP-element's name (string) and a table with the
contents of the SOAP Body.require "soap/http" local ns, meth, ent = soap.http.call ("http://soap.4s4c.com/ssss4c/soap.asp", "http://simon.fell.com/calc", "doubler", { { tag = "nums", attr = { ["xmlns:SOAP-ENC"] = "http://schemas.xmlsoap.org/soap/encoding/", ["SOAP-ENC:arrayType"] = "xsd:int[5]", }, { tag = "number", 10 }, { tag = "number", 20 }, { tag = "number", 30 }, { tag = "number", 50 }, { tag = "number", 100 }, }, }) print("namespace = ", ns, "element name = ", meth) for i, elem in ipairs (ent[1]) do print (elem[1]) end