Forum OpenACS Development: Re: XML request Versus SOAP response

Collapse
Posted by Claudio Pasolini on
Hi Iuri,

I tried tclsoap many years ago, but in my opinion tsclws (https://core.tcl-lang.org/tclws/doc/Release_2.6.2/docs/index.html) is a much better choice.

The only caveat is that if you have to call an existing web service you are limited to document/literal and rpc/encoded.

Ciao,

Claudio

Collapse
Posted by Russell Sorensen on
Are you interested in using a client to interact with an existing service, or are you trying to setup a server on OpenACS to respond to client requests?

The best tcl client is tclws as mentioned by Claudio Pasolini. I think my server is better overall. The software is available on gitHub:

https://github.com/russell-todd-sorensen/twist

You can see a service in action at:
https://www.semitasker.com/twist/ws/openacs/

The file you write to create the above service is this (saved as index.tcl somewhere under pageroot):

# Examples Using OpenACS data types:
# Regular expressions were taken from openacs.org, and
# use is covered by their license.
<ws>namespace init ::openacs

# Initialize Schema
<ws>namespace schema ::openacs "https://www.semitasker.com/twist/ws/openacs/"

### Simple Types

# Phone
<ws>type pattern openacs::phone {^\(?([1-9][0-9]{2})\)?(-|\.|\ )?([0-9]{3})(-|\.|\ )?([0-9]{4})};

# Email
<ws>type pattern openacs::email  {^[^@\t ]+@[^@.\t]+(\.[^@.\n ]+)+$};

# NaturalNum
<ws>type pattern openacs::naturalNum {^(0*)(([1-9][0-9]*|0))$} xsd::integer

# Operations for the service:
<ws>proc ::openacs::CheckEmail {
    {Email:openacs::email}
} {
    return [list "$Email" "True"]
} returns {Email:openacs::email IsEmail:boolean}

<ws>proc ::openacs::CheckPhone {
    {Phone:openacs::phone}
} {
    return [list $Phone True]
} returns {Phone:openacs::phone IsPhone:boolean}

<ws>proc ::openacs::CheckNaturalNumber {
    {NaturalNumber:openacs::naturalNum}
} {
    return [list $NaturalNumber True]
} returns {NaturalNumber:openacs::naturalNum IsNaturalNum:boolean}

<ws>namespace finalize ::openacs

<ws>namespace freeze ::openacs

<ws>return ::openacs

Additional running examples are here:
https://www.semitasker.com/twist/ws/datetime/
https://www.semitasker.com/twist/ws/mywebservice/
https://www.semitasker.com/twist/ws/stockquoter/
https://www.semitasker.com/twist/ws/stockquoter2/

You will be limited to document/literal but I have been considering putting in a json to json adapter.

These example services also expose some of the client functionality. If you click on one of the operation links, you are presented with an auto-generated form. Fill out the form and it is sent as a GET request to the server. This is converted into a client SOAP/document/literal format and resubmitted to the same url as a POST. I never got around to exploiting this, but it would be relatively straightforward to create a proxy service.