Library - wsserver

wsserver is a library which implements servers used for web services. Two protocols are supported: XML-RPC, a simple protocol based on XML and HTTP, and SOAP, a more complicated protocol also based on XML. While SOAP can be used with different transfer protocols, wsserver uses exclusively the most common one, HTTP.

wsserver maps calls sent by remote clients to LME functions. To use it, write an LME function for each method which can be called, with standard LME input and output arguments. XML-RPC methods receive directly their parameters an input arguments, while SOAP methods get a single structure whose fields correspond to named parameters. Then start an XML-RPC or SOAP on a free TCP/IP port with wsserverstart, and add each method with wsserveraddmethod.

The following statement makes available functions defined in wsserver:

use wsserver;

wsserver requires thread support, TCP/IP, and web services.

Examples

Here is an example of creating an XML-RPC server and testing it:

use wsserver;
wsserverstart('xmlrpc',8888);
wsserveraddmethod('sin',@sin,8888);
xmlrpccall('http://localhost:8888/','sin',[],1)

And here is its equivalent with SOAP:

use wsserver;
wsserverstart('soap',8889);
wsserveraddmethod('args',@dumpvar,8889);
params = {param1=1, param2=true};
soapcall('http://localhost:8889/','args','ns','',[],params)

Functions

wsserveraddmethod

Add a new method to an XML-RPC or SOAP server.

Syntax

use wsserver
wsserveraddmethod(name, fun, port)

Description

wsserveraddmethod(name,fun,port) adds a new method to the XML-RPC or SOAP server on the specified TCP/IP port. The method name which must be given by the client is the string name. The implementation is provided by the function fun, which can be a function reference, an inline function or a function name as a string. For XML-RPC, fun must accept all the input arguments provided by the client (it can be variable, and obtained with nargin); for SOAP, fun must accept a single input argument, which is a structure whose fields contain the named parameters of the SOAP call. For both protocols, sun responds with a single output argument which is sent to the client as the response; if it does not have any output argument, the response is the integer number 0. The number of methods is limited only by memory.

Examples

XML-RPC method which computes the sine of its single parameter:

use wsserver;
wsserveraddmethod('sin', @sin, 8888);

XML-RPC parameterless method which returns the current time:

wsserveraddmethod('currentTime', @clock, 8888);

Implementation of an XML-RPC method which accepts a variable number of parameters, which must be numbers, and responds with the largest of them:

function response = largest(varargin)
  response = max(list2num(varargin));

This method is added with

wsserveraddmethod('largest', @largest, 8888);

SOAP method which computes the argument of a complex number given as named parameters x and y:

function response = argument(param)
  response = atan2(param.y, param.x);

See also

wsserverstart

wsserverstart

Start XML-RPC or SOAP server.

Syntax

use wsserver
wsserverstart(protocol, port)

Description

wsserverstart('xmlrpc',port) starts an XML-RPC server on the specified TCP/IP port. wsserverstart('soap',port) starts a SOAP server. In both cases, the default port is 80 (the standard port of HTTP, the transfer protocol used by XML-RPC and this SOAP implementation). Only one server can listen to a given port on the same computer.

Example

use wsserver;
wsserverstart('xmlrpc',8888)

See also

wsserveraddmethod, wsserverstop

wsserverstop

Stop XML-RPC or SOAP server.

Syntax

use wsserver
wsserverstop(port)

Description

wsserverstop(port) stop the XML-RPC or SOAP server on the specified TCP/IP port.

See also

wsserverstart


Copyright 2005-2014, Calerga.
All rights reserved.