luaSOAP client

894 views
Skip to first unread message

bfmtl

unread,
Sep 16, 2012, 1:20:16 PM9/16/12
to kepler-...@googlegroups.com
Hello,

I'm trying to make the small SOAP LUA client provided on the luaSOAP work with a free web service that gives city data based on a provided US Zip code 
http://www.webservicex.net/uszip.asmx?WSDL This web service works as I tested it in generic SOAP client. My goal is to write a generic LUA SOAP client function based on luaSOAP. Please see attached screenshots.
 
The script I run is:
============================
local client = require "soap.client"
local ns, meth, ent = client.call {
        method = "GetInfoByZIP",
        soapaction = "http://www.webserviceX.NET/GetInfoByZIP",
        entries = { -- `tag' will be filled with `method' field
                {
                        tag = "USZip",
                        attr = {
                                ["xmlns:SOAP-ENC"] = "http://schemas.xmlsoap.org/soap/encoding/",
                                ["SOAP-ENC:arrayType"] = "xsd:string[1]",
                        },
                        { tag = "USZip", "33322" },
                },
        }
}
print("namespace = ", ns, "element name = ", meth)
for i, elem in ipairs (ent[1]) do
        print (elem[1])
end
============================

and returns the following error message:

lua: /usr/share/lua/5.1/soap/client.lua:96: Error while decoding: ./soap.lua:239: attempt to index local 'o' (a nil value)

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetInfoByZIPResponse xmlns="http://www.webserviceX.NET" /></soap:Body></soap:Envelope>
stack traceback:
[C]: in function 'assert'
/usr/share/lua/5.1/soap/client.lua:96: in function 'call'
testsoap.lua:2: in main chunk
[C]: ?


Could you please let me know what I did wrong? Is there additional luaSOAP documentation available?

Thank you very much.  

Bernard

Tomas Guisasola Gorham

unread,
Sep 18, 2012, 7:39:14 AM9/18/12
to bf...@hotmail.com, kepler-...@googlegroups.com
Hi Bernard

On Sun, 16 Sep 2012, bfmtl wrote:
> *lua: /usr/share/lua/5.1/soap/client.lua:96: Error while decoding:
> ./soap.lua:239: attempt to index local 'o' (a nil value)*
> *
> *
> *<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="
> http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="
> http://www.w3.org/2001/XMLSchema"><soap:Body><GetInfoByZIPResponse xmlns="
> http://www.webserviceX.NET <http://www.webservicex.net/>"
> /></soap:Body></soap:Envelope>*
> *stack traceback:*
> * [C]: in function 'assert'*
> * /usr/share/lua/5.1/soap/client.lua:96: in function 'call'*
> * testsoap.lua:2: in main chunk*
> * [C]: ?*
>
>
> Could you please let me know what I did wrong? Is there additional luaSOAP
> documentation available?
I'm getting another error (which is not good anyway). What
version do you have installed? I'm taking a look at your problem and
will provide some feedback soon.

Regards,
Tom�s

Tomas Guisasola Gorham

unread,
Sep 18, 2012, 8:53:50 AM9/18/12
to BF, kepler-...@googlegroups.com
Hi Bernard

You can send that kind of information in text :-) I hope the
version of the soap/client.lua file is 1.9 from the same day...
Well, I cannot reproduce your error and what I am getting is
from the fact that the response is an empty table, so there is no ent[1].

Anyway, there is something strange, because my soap.lua file
(I've just downloaded it again from LuaRocks repo) only have 209 lines,
so how could it be running line 239? Also, file soap/client.lua have
only 85 lines, and your message refers to line 96! Are you sure the
script is loading the appropriate libraries? Maybe you have an old
version installed anywhere...

Regards,
Tom�s

On Tue, 18 Sep 2012, BF wrote:

> Hi Tomas,
>
> Thank you for your message. Please find attached 2 screenshots for Lua and luaSOAP versions from soap.lua.
>
> Thank you.
>
> Bernard
--

BF

unread,
Sep 18, 2012, 9:23:57 AM9/18/12
to kepler-...@googlegroups.com
Hi Tomas,

I have installed it from Ubuntu Software Center GUI as I have not been able to install it from LuaRocks. Should I just overwrite the current soap.lua and client.lua files with the one available from download?

Regards,

Bernard

On Sep 18, 2012, at 8:53 AM, Tomas Guisasola Gorham wrote:

> Hi Bernard
>
> You can send that kind of information in text :-) I hope the
> version of the soap/client.lua file is 1.9 from the same day...
> Well, I cannot reproduce your error and what I am getting is
> from the fact that the response is an empty table, so there is no ent[1].
>
> Anyway, there is something strange, because my soap.lua file
> (I've just downloaded it again from LuaRocks repo) only have 209 lines,
> so how could it be running line 239? Also, file soap/client.lua have
> only 85 lines, and your message refers to line 96! Are you sure the
> script is loading the appropriate libraries? Maybe you have an old
> version installed anywhere...
>
> Regards,
> Tomás
>>> Tomás
>>
>>
>
> --
>

Tomas Guisasola Gorham

unread,
Sep 18, 2012, 9:37:17 AM9/18/12
to kepler-...@googlegroups.com
Hi Bernard

> I have installed it from Ubuntu Software Center GUI as I have not been able to install it from LuaRocks. Should I just overwrite the current soap.lua and client.lua files with the one available from download?
I don't know what kind of "solution" do you want. I would
try to make LuaRocks works, since new versions of Lua software become
available there sooner than through other software distributions.
Suppose that we found that your problem is a bug in LuaSOAP. Then I
fixed it and you'll have to install a new version. I think you'll have
to wait months to have it provided by Ubuntu Software Center, but it will
become available at LuaRocks in a couple of days. From my point of view,
it is a better solution. But if you just want to "run the script once",
then you can overwrite the files...

Regards,
Tom�s

BF

unread,
Sep 18, 2012, 9:50:42 AM9/18/12
to kepler-...@googlegroups.com
Hi Tomas,

My objective is to be able to call SOAP web services from a lua script. When running "luarocks install luasoap" I get:

root@wagner:/usr/share/lua/5.1/soap# luarocks install luasoap
Archive:  /tmp/luarocks_luarocks-rock-luasoap-2.0.2-1-7067/luasoap-2.0.2-1.all.rock
   creating: doc/
   creating: doc/us/
  inflating: doc/us/examples.html    
  inflating: doc/us/index.html       
  inflating: doc/us/license.html     
  inflating: doc/us/luasoap.png      
  inflating: doc/us/manual.html      
   creating: lua/
   creating: lua/soap/
  inflating: lua/soap/client.lua     
  inflating: lua/soap/server.lua     
  inflating: lua/soap.lua            
  inflating: luasoap-2.0.2-1.rockspec  
  inflating: rock_manifest           

Missing dependencies for luasoap:
luaexpat >= 1.1.0-3
luasocket >= 2.0.2-1

Archive:  /tmp/luarocks_luarocks-rock-luaexpat-1.2.0-1-9958/luaexpat-1.2.0-1.src.rock
  inflating: luaexpat-1.2.0-1.rockspec  
 extracting: luaexpat-1.2.0.tar.gz   
gcc -O2 -I/usr/include/lua5.1 -c src/lxplib.c -o src/lxplib.o -I/usr/include -Isrc/
gcc -shared -o lxp.so -L/usr/local/lib src/lxplib.o -L/usr/lib -lexpat
/usr/bin/ld: src/lxplib.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
src/lxplib.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
cp: cannot stat `lxp.so': No such file or directory

Error: Failed installing dependency: http://luarocks.org/repositories/rocks/luaexpat-1.2.0-1.src.rock - Build error: Build error
root@wagner:/usr/share/lua/5.1/soap# luarocks install luaexpat
Archive:  /tmp/luarocks_luarocks-rock-luaexpat-1.2.0-1-1467/luaexpat-1.2.0-1.src.rock
  inflating: luaexpat-1.2.0-1.rockspec  
 extracting: luaexpat-1.2.0.tar.gz   
gcc -O2 -I/usr/include/lua5.1 -c src/lxplib.c -o src/lxplib.o -I/usr/include -Isrc/
gcc -shared -o lxp.so -L/usr/local/lib src/lxplib.o -L/usr/lib -lexpat
/usr/bin/ld: src/lxplib.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
src/lxplib.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
cp: cannot stat `lxp.so': No such file or directory

Error: Build error: Build error

Any thoughts? Sorry I'm new to this.

Regards

Bernard 

Tomás


Tomas Guisasola Gorham

unread,
Sep 18, 2012, 9:56:02 AM9/18/12
to kepler-...@googlegroups.com
Hi Bernard

Change the way you call luarocks from:

luarocks install luasoap

to:

luarocks install luasoap CFLAGS=-fPIC

I think it would make it.
By the way, what version of LuaRocks are you using?

Regards,
Tom�s

BF

unread,
Sep 18, 2012, 10:08:12 AM9/18/12
to kepler-...@googlegroups.com
Hi Tomas,

It's getting better now. Luarocks could install luaSOAP. Please see below:
-rwxr-xr-x 1 root root 6696 2012-09-18 09:58 /usr/local/share/lua/5.1/soap.lua

The code provided here for your review now returns

namespace = http://www.w3.org/2001/XMLSchema-instance element name = GetInfoByZIPResponse
lua: testsoap.lua:18: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
[C]: in function 'ipairs'
testsoap.lua:18: in main chunk
[C]: ?

I think the problem is now in my test client.

Bernard.
> Tomás
>

Tomas Guisasola Gorham

unread,
Sep 18, 2012, 10:14:43 AM9/18/12
to kepler-...@googlegroups.com
Hi Bernard

> It's getting better now. Luarocks could install luaSOAP.
Great!

> Please see below:
> -rwxr-xr-x 1 root root 6696 2012-09-18 09:58 /usr/local/share/lua/5.1/soap.lua
>
> The code provided here for your review now returns
>
> namespace = http://www.w3.org/2001/XMLSchema-instance element name = GetInfoByZIPResponse
> lua: testsoap.lua:18: bad argument #1 to 'ipairs' (table expected, got nil)
> stack traceback:
> [C]: in function 'ipairs'
> testsoap.lua:18: in main chunk
> [C]: ?
>
> I think the problem is now in my test client.
Sure. The table is empty.

Regards,
Tom�s

Alexander Gladysh

unread,
Sep 18, 2012, 10:14:41 AM9/18/12
to kepler-...@googlegroups.com
On Tue, Sep 18, 2012 at 5:56 PM, Tomas Guisasola Gorham
<to...@tecgraf.puc-rio.br> wrote:
> Hi Bernard
>
> Change the way you call luarocks from:
>
> luarocks install luasoap
>
> to:
>
> luarocks install luasoap CFLAGS=-fPIC

If a modern LR is used, this looks like a bug in a rockspec. Please
report it to Hisham.

Thanks,
Alexander

BF

unread,
Sep 18, 2012, 10:27:05 AM9/18/12
to kepler-...@googlegroups.com
Alexander,

LR version = 2.0.1

Thanks

Bernard

Alexander Gladysh

unread,
Sep 18, 2012, 10:28:35 AM9/18/12
to kepler-...@googlegroups.com
On Tue, Sep 18, 2012 at 6:27 PM, BF <bf...@hotmail.com> wrote:
> On Sep 18, 2012, at 10:14 AM, Alexander Gladysh wrote:
>> On Tue, Sep 18, 2012 at 5:56 PM, Tomas Guisasola Gorham

>>> luarocks install luasoap CFLAGS=-fPIC
>>
>> If a modern LR is used, this looks like a bug in a rockspec. Please
>> report it to Hisham.

> LR version = 2.0.1

Please upgrade. Current version is 2.0.10.

Alexander.

Tomas Guisasola Gorham

unread,
Sep 18, 2012, 10:29:21 AM9/18/12
to kepler-...@googlegroups.com
Hi Bernard and Alexander

On Tue, 18 Sep 2012, BF wrote:
> LR version = 2.0.1
I think the problem with the "CFLAGS=-fPIC" is the expected
behavior of this version of LuaRocks.

Regards,
Tom�s

Alexander Gladysh

unread,
Sep 18, 2012, 10:35:41 AM9/18/12
to kepler-...@googlegroups.com
Indeed so. No bug report is necessary.

Thanks,
Alexander.

BF

unread,
Sep 18, 2012, 11:06:09 AM9/18/12
to kepler-...@googlegroups.com
Hi Tomas,

I'm not clear on this. Yes table is empty. I like to make a Lua generic SOAP client. My understanding is that web service is called but with wrong input values.
The http://www.webservicex.net/uszip.asmx?WSDL file expects a USZip code entry param

A generic SOAP 

<soap:Envelope>
<soap:Body>
<GetInfoByZIPResponse>
<GetInfoByZIPResult>
<NewDataSet>
<Table>
<CITY>Sunrise</CITY>
<STATE>FL</STATE>
<ZIP>33322</ZIP>
<AREA_CODE>954</AREA_CODE>
<TIME_ZONE>E</TIME_ZONE>
</Table>
</NewDataSet>
</GetInfoByZIPResult>
</GetInfoByZIPResponse>
</soap:Body>
</soap:Envelope>

My understanding is that ent array should be ent["CITY"]=Sunrise, ent[STATE]=FL and so on

Is my 'entries' OK to pass USZip=33322? I took it from luaSOAP site client exemple

       entries = { -- `tag' will be filled with `method' field
                {
                        tag = "USZip",
                        attr = {
                                ["xmlns:SOAP-ENC"] = "http://schemas.xmlsoap.org/soap/encoding/",
                                ["SOAP-ENC:arrayType"] = "xsd:string[1]",
                        },
                        { tag = "USZip", "33322" },
                },
        }

I'm not clear on the difference between red and blue tag. 

Thanks again 

Bernard
  

Tomás


Tomas Guisasola Gorham

unread,
Sep 18, 2012, 1:15:40 PM9/18/12
to kepler-...@googlegroups.com
Hi Bernard

> I'm not clear on this. Yes table is empty. I like to make a Lua generic SOAP client. My understanding is that web service is called but with wrong input values.
Yes. I think it is missing the `namespace' entry.

> The http://www.webservicex.net/uszip.asmx?WSDL file expects a USZip code entry param
Although the service works with this URL, I think the `?WSDL'
is unnecessary...

> A generic SOAP
> (http://www.soapclient.com/soapclient?template=%2Fclientform.html&fn=soapform&SoapTemplate=%2FSoapResult.html&SoapWSDL=http%3A%2F%2Fwww.webservicex.net%2Fuszip.asmx%3FWSDL&_ArraySize=2) client returns for that WSDL:
>
> <soap:Envelope>
> <soap:Body>
> <GetInfoByZIPResponse>
> <GetInfoByZIPResult>
> <NewDataSet>
> <Table>
> <CITY>Sunrise</CITY>
> <STATE>FL</STATE>
> <ZIP>33322</ZIP>
> <AREA_CODE>954</AREA_CODE>
> <TIME_ZONE>E</TIME_ZONE>
> </Table>
> </NewDataSet>
> </GetInfoByZIPResult>
> </GetInfoByZIPResponse>
> </soap:Body>
> </soap:Envelope>
>
> My understanding is that ent array should be ent["CITY"]=Sunrise, ent[STATE]=FL and so on
Not exactly. See below.

> Is my 'entries' OK to pass USZip=33322? I took it from luaSOAP site client exemple
>
> entries = { -- `tag' will be filled with `method' field
> {
> tag = "USZip",
> attr = {
> ["xmlns:SOAP-ENC"] = "http://schemas.xmlsoap.org/soap/encoding/",
> ["SOAP-ENC:arrayType"] = "xsd:string[1]",
> },
> { tag = "USZip", "33322" },
> },
> }
No. This is equivalent to "<USZip><USZip>33322</USZip></USZip>"
since you've put two tables with tag=="USZip".

The following script will make it work:

#!/usr/bin/lua -lluarocks.require
local client = require "soap.client"
local ns, meth, ent = client.call {
url = "http://www.webservicex.net/uszip.asmx", -- removed the final "?WSDL" part
method = "GetInfoByZIP",
namespace = "http://www.webserviceX.NET", -- I think this entry is obligatory
soapaction = "http://www.webserviceX.NET/GetInfoByZIP",
entries = {
{ tag = "USZip", "33322", },
},
}
print("namespace = ", ns, "element name = ", meth)

if next(ent) then -- not an empty table
assert (ent[1].tag == "GetInfoByZIPResult", "Unexpected response tag: "..tostring (ent[1].tag))
assert (ent[1][1].tag == "NewDataSet", "Unexpected response data set: "..tostring (ent[1][1].tag))
assert (ent[1][1][1].tag == "Table", "Unexpected response table: "..tostring (ent[1][1][1].tag))
for i, elem in ipairs (ent[1][1][1]) do
print (i, elem[1])
end
end

I've added some assert calls to make sure everything is ok.
Note that the real structure is somewhat deeper than you were expecting
(this is the simplicity on SOAP :-)

Regards,
Tom�s

BF

unread,
Sep 18, 2012, 1:42:50 PM9/18/12
to kepler-...@googlegroups.com
Hi Tomas,

Thank you very much for your help. It works now. FYI, I tried your code without namespace: It did not work. I had to put namespace back to make it work again.

I understand that user must provide URL, method and input params for web service to execute correctly. Is this the same for "soapaction" and "namespace"?

Thank you

Bernard
> Tomás
>

Tomas Guisasola Gorham

unread,
Sep 18, 2012, 2:14:06 PM9/18/12
to kepler-...@googlegroups.com
Hi Bernard

> Thank you very much for your help. It works now. FYI, I tried your code without namespace: It did not work. I had to put namespace back to make it work again.
Yes, I checked that too, but cannot say why.

> I understand that user must provide URL, method and input params for web service to execute correctly. Is this the same for "soapaction" and "namespace"?
"SOAPAction" is an HTTP header mandatory in SOAP version 1.1 (I
think); if you specify soapversion=1.2, you must not provide a soapaction.
"namespace" is used to build an attribute of the XML document,
but I can't explain the rationale for that...

Regards,
Tom�s

BF

unread,
Sep 18, 2012, 2:16:05 PM9/18/12
to kepler-...@googlegroups.com
Hi Tomas,

Again thank you so much for your help.

Regards,

Bernard
> Tomás
>

BF

unread,
Sep 18, 2012, 6:52:27 PM9/18/12
to kepler-...@googlegroups.com
Hi Tomas,

The web service returns several fields in then <table> tag.
<soap:Envelope><soap:Body><GetInfoByZIPResponse><GetInfoByZIPResult><NewDataSet><Table><CITY>Sunrise</CITY><STATE>FL</STATE><ZIP>33322</ZIP><AREA_CODE>954</AREA_CODE><TIME_ZONE>E</TIME_ZONE></Table></NewDataSet></GetInfoByZIPResult></GetInfoByZIPResponse></soap:Body></soap:Envelope>

Do you know how I can reference each field by its name rather by its position in table or how I get get the tag name for each of the field?

Thank you

Regards,

Bernard
> Tomás
>

Tomas Guisasola Gorham

unread,
Sep 19, 2012, 7:44:24 PM9/19/12
to kepler-...@googlegroups.com
Hi Bernard

> The web service returns several fields in then <table> tag.
> <soap:Envelope><soap:Body><GetInfoByZIPResponse><GetInfoByZIPResult><NewDataSet><Table><CITY>Sunrise</CITY><STATE>FL</STATE><ZIP>33322</ZIP><AREA_CODE>954</AREA_CODE><TIME_ZONE>E</TIME_ZONE></Table></NewDataSet></GetInfoByZIPResult></GetInfoByZIPResponse></soap:Body></soap:Envelope>
>
> Do you know how I can reference each field by its name rather by its position in table or how I get get the tag name for each of the field?
The table returned by the function soap.client.http.call()
follows the LOM format, which aims to represent the exact XML structure.
But many times the web services use a subset of it. The above seems to
avoid attributes.
We developed a small library to convert LOM format to simpler
ones, when it is possible. If I have some more time I'll pack it
and distribute. For now, I think a very useful function for your case
is find_elem():

Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> lom=require"lxp.lom"
> function find_elem (self, tag)
>> for k = 1, #self do
>> local v = self[k]
>> if type (v) == "table" then
>> if v.tag == tag then
>> return v
>> else
>> local temp = find_elem (v, tag)
>> if temp then
>> return temp
>> end
>> end
>> end
>> end
>> return nil
>> end
> o = lom.parse[[<soap:Envelope><soap:Body><GetInfoByZIPResponse><GetInfoByZIPResult><NewDataSet><Table><CITY>Sunrise</CITY><STATE>FL</STATE><ZIP>33322</ZIP><AREA_CODE>954</AREA_CODE><TIME_ZONE>E</TIME_ZONE></Table></NewDataSet></GetInfoByZIPResult></GetInfoByZIPResponse></soap:Body></soap:Envelope>]]
> =find_elem (o, 'CITY')[1]
Sunrise

Regards,
Tom�s

BF

unread,
Sep 19, 2012, 8:05:41 PM9/19/12
to kepler-...@googlegroups.com
Hi Tomas,

Thanks again for your help.

Regards,

Bernard
> Tomás
>

mithlesh upadhyay

unread,
Dec 28, 2012, 12:23:39 PM12/28/12
to kepler-...@googlegroups.com
Hi All

I am new in lua.I need some help in lua.I have created a webservice and i want access that web services in lua and  invoke web services  method in lua.
Please give me your idea /suggestion .

Thanks 
Mithlesh

Tomas Guisasola Gorham

unread,
Jan 2, 2013, 3:12:29 PM1/2/13
to kepler-...@googlegroups.com
Hi Mithlesh

> I am new in lua.I need some help in lua.I have created a webservice and i
> want access that web services in lua and invoke web services method in
> lua.
> Please give me your idea /suggestion .
Have you tried LuaSOAP? I feel quite comfortable with it :-)

Regards,
Tom�s

Mehmet KARA

unread,
Apr 8, 2014, 10:46:53 AM4/8/14
to kepler-...@googlegroups.com
   Hi bfmtl,

It is irrelevant a little bit but I am new at lua.  I want to call C# web service on lua but I could't,

I have still take error. It says;

"Module  Soap.lua" not found:n resource (sopa.client.lu) does not exist in archive..

I have tried  "luarocks install luasoap" on command window but it does not work.

Can you tell me how I fix it?


thanks for answer








20 Eylül 2012 Perşembe 03:05:49 UTC+3 tarihinde bfmtl yazdı:

Tomas Guisasola Gorham

unread,
Apr 10, 2014, 10:00:01 AM4/10/14
to kepler-...@googlegroups.com
Hi Mehmet KARA

Sorry for the late response. In fact I can't remember if someone
answered you. Forgive me if I am duplicating the answer.
You gave little information about your problem, but assuming the
message is correct, it seems you have a typo in the name of the module
being require'd. The messagem says "sopa.client.lu", while the module
might be "soap.client". Please, check this first.

Regards,
Tomás

On Tue, 8 Apr 2014, Mehmet KARA wrote:

> Hi bfmtl,
>
> It is irrelevant a little bit but I am new at lua. I want to call C# web
> service on lua but I could't,
>
> I have still take error. It says;
>
> "Module Soap.lua" not found:n resource (sopa.client.lu) does not exist in
> archive..
>
> I have tried "luarocks install luasoap" on command window but it does not
> work.
>
> Can you tell me how I fix it?
>
>
> thanks for answer
>
>
>
>
>
>
>
>
> 20 Eylül 2012 Perÿÿembe 03:05:49 UTC+3 tarihinde bfmtl yazdÿÿ:
--
Reply all
Reply to author
Forward
0 new messages