The library uses gSoap and its httpget and httpform plugins for handling HTTP request. That means that you can serve web pages and process CGI request by Z-Script. A Z-Script module used as CGI will get two variables: HTTP_SOAP and HTTP_PARS. The former is a user object and can be used to call functions in the following table; and the later is an array that contains all GET or POST parameters.
The library also implements interfaces for passing data of integer, real, string, and binary between applications using SOAP.
| Function | Parameter Type | Remark |
| soap([io, access, alive]) | integers | Returns a SOAP object. Use the optional parameters of io to specify send/receive timeout in second (default =60), access to specify access timeout (default=600), and alive to specify keep-alive (default=100). |
| .mine(ext) | string | Sets MINE content type of response according file extension. |
| .log(fname) | string | logs access information to the file. |
| .proxy(name, port) | string, integer | Uses the proxy to access server. |
| .request(http, service, p1[, p2, ...]) | string, string, string|integer|real|array | Sends server (http) with the service name and variable number of parameters. If an array parameter is used, it is expected to have two items with the first being the pointer to binary data and the second being the number of bytes. The service name is the function name on the server side. |
| .send(str) | string | Sends to client HTML content in text. |
| .send(ptr, n) | user, integer | Sends to client n-bytes of raw data. Note that the content type must be set properly. |
| .serve(fname, [port]) | string, integer | Starts SOAP server. The server create a number of threads which have their own modules loaded from the script file. The optional parameter may be used to specify the port number (default=80). The server may response to clients with a string, an integer, a real, or an array of two items with the first being the pointer to binary data and the second being the number of bytes. |
| .user(usr, psw) | string, string | Sets client user name and password. |
/********************** Server.zs **********************************/
load("soap.dll");
sp = soap();
sp.serve("Service.zs");
/********************** Service.zs *******************************/
function p1_func(p)
{
csv(p);
return "Response: " + p;
}
function p3_func(p1, p2, p3)
{
csv(p1, p2, p3);
return "Response: p1=" + p1 + " p2=" + p2 + " p3=" + p3;
}
function b_func(p)
{
csv(p);
if (!isarray(p)) {
csv("Client parameter is not an array.");
return;
}
// return whatever binary from the client
return p;
}
/********************** Client.zs ***********************************/
load("soap.dll", "matrix.dll");
sp = soap();
url = "localhost";
a = sp.request(url, "p1_func", "Hi!");
csv(a);
a = sp.request(url, "p1_func", 100);
csv(a);
a = sp.request(url, "p1_func", 100.5);
csv(a);
a = sp.request(url, "p3_func", "Hi!", 100, 100.5);
csv(a);
D = matrix("double", 10);
D.fill(10, 1);
[ptr, m, e] = D.ptr();
[ptr, n] = sp.request(url, "b_func", [ptr, m*e]);
M = matrix("double", 10);
M.import(ptr);
M.print();
/********************** Server.zs **********************************/
load("soap.dll");
sp = soap();
sp.serve("Service.zs");
/********************** test.zs *******************************
* 1. Prepare index.html with a form that has a text field
* named p1 and a submit button. Set the form's action to
* "test.zs".
* 1. Start the server program by the command
* zs.exe server.zs
* 2. Start web browser and type http://localhost/index.html
* in its address bar.
* 3. Type in the text field of the form and click submit.
*
* You will see whatever you have typed.
**************************************************************/
HTTP_SOAP.send("<p>" + HTTP_PARS["p1"] + "</p>");