In this article by Damitha Kumarage, he describes calling Web services from a shell environment.
Introduction
WSF/C framework is a feature rich Web services platform implemented in the C language and is built around the various Apache WS-* implementations like the Axis2/C Web services engine, the Sandesha2/C Reliable Messaging Implementation, the Rampart/C WS-Security implementation and the Savan/C WS-Eventing implementation. Based on WSF/C implementation, there are other successful scripting language specific Web Services platforms like WSF/PHP, WSF/Perl, WSF/Ruby, and, there are also browser plugins written using WSF/C framework to enable browsers(currently for Firefox and IE) with Web services. It is only very natural for one to expect the ability from command line shells to invoke Web services. wsclient is a tool for this purpose. It is currently implemented and tested in Linux and Windows platforms. Many of you may be familiar with the wget command line tool. wget is a non-interactive network receiver which could be very handy in certain situations. The analogy between wget and wsclient is, that like wget is for http interaction from command line, wsclient is for Web services invocation from command line. wsclient has support for both SOAP and Rest like invocations. It should be noted that wsclient can also be effectively used as a great testing tool for your wire SOAP formats.
Applies To
| WSF/C | 1.2.0, 1.2.1 |
| Axis2/C | 1.3.0 |
| Environment | Linux - Debian Etch/Lenny, Ubuntu, Fedora, Windows |
Table of Contents
- Installing wsclient [0]
- Calling Web Services [0]
- Http Options [0]
- SOAP Options [0]
- Addressing Options [0]
- MTOM Options [0]
- Rampart Options [0]
- SSL Options [0]
- Amazon Client Sample [0]
- Flicker Photo Search Sample [0]
- Handling Attachments [0]
- Security with wsclient [0]
- Summary [0]
- Resources [0]
Before continuing with this article, please note that I expect you to be familiar with the Axis2/C Web services platform. Apache Axis2/C - Web Services Engine [0] is a good reading to get you started. All the samples in this article uses wsclient tool, in Linux bash shell. All these could be similarly performed on a Windows shell as well.
WSF/C download [0] page. Installations are available for Windows, Debian and rpm. Once installed you are ready to play with wsclient.
Amazon ecommerce Client [1]. Here, we will look at a small sample script that does an item search on Amazon ecommerce Service.
wsclient --soap1.1 --no-mtom --action http://soap.amazon.com
http://soap.amazon.com:80/onca/soap?Service=AWSECommerceService < item_search.xml
wsclient --soap1.1 --no-mtom --action http://soap.amazon.com http://soap.amazon.com:80/onca/soap?Service=AWSECommerceService < item_search.xml
Contents of the item_search.xml is
<ItemSearch xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05">
<AWSAccessKeyId>Access Key</AWSAccessKeyId>
<Request>
<ResponseGroup>Medium</ResponseGroup>
<ItemPage>1</ItemPage>
<Keywords>Web Services</Keywords>
<SearchIndex>Books</SearchIndex>
</Request>
</ItemSearch>To try this sample, you must obtain an access Key from Amazon AWS [2] .
Flicker [3] . This will return all information related to the photos that match the search keyword "peace". We can also make a Rest invocation using the following command:
echo "flickr.photos.search$1peace" | $WSFC_HOME/bin/wsclient --get
http://api.flickr.com/services/rest/?method=flickr.photos.search
Here, we don't use SOAP binding and use get as the http request method.
Rampart/C [4] . A Quick Reference Guide for Rampart/C Configurations [4] is a good place to learn more about implementing security with Rampart/C. You can specify username, password pairs or password files for most basic authentication scenarios as the following:
wsclient --soap --no-mtom --user alice --digest --password
password http://localhost:9090/axis2/services/sec_echo
<$WSFC_HOME/bin/samples/wsclient/data/echo.xml
Note that, --digest option above, is for password digest for the username token.
To perform signing:
wsclient --soap --no-mtom --timestamp --sign-body --key $WSFC_HOME/bin/samples/rampart/keys/ahome/alice_key.pem --certificate $WSFC_HOME/bin/samples/rampart/keys/ahome/alice_cert.cert --recipient-certificate $WSFC_HOME/bin/samples/rampart/keys/ahome/bob_cert.cert http://localhost:9090/axis2/services/sec_echo <$WSFC_HOME/bin/samples/wsclient/data/echo.xml
To perform encryption and signing
wsclient --soap --no-mtom --timestamp --sign-body --key $WSFC_HOME/bin/samples/rampart/keys/ahome/alice_key.pem --certificate $WSFC_HOME/bin/samples/rampart/keys/ahome/alice_cert.cert --recipient-certificate $WSFC_HOME/bin/samples/rampart/keys/ahome/bob_cert.cert --encrypt-payload http://localhost:9090/axis2/services/sec_echo <$WSFC_HOME/bin/samples/wsclient/data/echo.xml
It should also be noted, that for all security scenarios described above, you can use the Rampart/C server sample called sec_echo. You may need to do some policy changes in the sec_echo server sample's service.xml for certain scenarios. For example, you may need to comment the Timestamp entry, if you are not sending a timestamp from wsclient.
WSO2 WSF/C [4]- WSO2 WSF/C is an Open Source framework for providing and consuming Web services
Author
Damitha Kumarage, Senior Software Engineer at wso2, committer Apache Software Foundation, damitha at wso2 dot com