property pInetId
property pSYfunction
property pSYinstance
on
new me
return me --constructor
end
on stepframe me
if netdone(pInetId) then --http-post was successful and return-value arrived
tINresult = script("xml.parser").new()
tINresult.parseString(nettextresult(pInetId))
--the returned string gets parsed
if not(voidP(tINresult.getelementbyname("*").getAProP("fault")))
then --check if a <fault> tag is
within the xml
tINresult = 0
end if
if objectP(pSYinstance) then
if symbolP(pSYfunction) then
call(pSYfunction,
pSYinstance, tINresult) --pSYinstance and
pSYfunction have been defined and get called now
end if
else
if symbolP(pSYfunction) then
do(pSYfunction&"(tINresult)") --just
pSYfunction was defined and the function gets called
else
put nettextresult(pInetId) --nothing
was defined and the string gets printed to the message window
end if
end if
repeat while (the actorlist).getpos(me)
(the actorlist).deleteone(me) --cleaning up the actorlist
end repeat
end if
end
on remotecall
me, tShost, tSmethodName, tLparameters, tSYfunction, tSYinstance
pSYfunction = tSYfunction
pSYinstance = tSYinstance
if stringP(tShost) AND stringP(tSmethodName)
then --if tShost and tSmethodName were
defined
tScall = "<?xml version=""E&"1.0""E&"?><methodCall><methodName>"
--the request gets encoded as xml
tScall =
tScall&tSmethodName&"</methodName>"
tScall = tScall & "<params>"
tScall = tScall & me.formatParameters(tLparameters) --the parameters get encoded
tScall = tScall & "</params></methodCall>"
pInetId = postnettext(tShost, tScall) --the request gets posted
(the actorlist).add(me)
else
return 0
end if
end
on formatParameters me, tLparameters
tString =
""
repeat with i = 1 to tLparameters.count
if not(ilk(tLparameters[i], #list)) then
--a single value
if ilk(tLparameters, #proplist) then
tString = tString &
"<member><name>" & tLparameters.getpropat(i) &
"</name>"
else
tString = tString &
"<param>"
end if
case ilk(tLparameters[i]) of :
#string :
tString = tString &
"<value><string>" & tLparameters[i] & "</string></value>" --string
#integer :
tString = tString &
"<value><i4>" & tLparameters[i] & "</i4></value>" --integer
#float : tString
= tString &
"<value><double>" & tLparameters[i] & "</double></value>" --float
end case
if ilk(tLparameters, #proplist) then
tString = tString &
"</member>"
else
tString = tString &
"</param>"
end if
else
case TRUE of :
(ilk(tLparameters[i],
#linearlist)) : tString = tString &
"<array>" & formatParameters(1, tLparameters[i]) &
"</array>" --linear lists
become an <array>
(ilk(tLparameters[i],
#proplist)) : tString = tString &
"<struct>" & formatParameters(1, tLparameters[i]) &
"</struct>" --proeperty list
are encoded as <struct>
end case
end if
end repeat
return tString
end