We will begin with a short description of the web-service I will use for these demo. Web services can be difficult to create but cannot (should not) be difficult to consume... Because of the relative complexity we have sometime to face, I decided to add some fun to this demo: I developed a web service using JWSDP (see Java Web Service Developer Pack 1.3) to interface my Lego RCX rover. This was possible by using Lejos API (see this wonderful system: Lejos at source forge). Well, for the time being you can just query the brick to have some info about memory, battery, internal clock, temperature and light sensor value. I will add more functionalities with the time.
With this documentation, I expect you will be able to create your own SOAP client based on Java, Php, Perl and Python, whatever the platform and/or operating system you are working on. You will find here several examples using these languages. My first goal is to share with you my experience using web-services by providing different ways to create a client and I hope you will have enough information to use these samples as templates for your use.
Here is the WSDL file of my RPC/encoded web service (Now I also have a document/literal version on-line). Check here if on-line. The WSDL file will be used by your client to know what functionalities are exposed, or directly by you to write by hand the SOAP message you will upload manually to the server! ;-) Oh yes, such examples will follow later. But we will try something more simple first. We are now going to focus to consume the method String readLS(String your_message) (simulation of a RCX light sensor reading, so the remote procedure will return a fixed string). Here is the WSDL you will get if you request it to my rpc/encoded web service. This file is an XML representation of the methods exposed by the web service (You can take a look at the items in bold). I will refer to this listing later when constructing our first client:
The first client we are going to build will be easy to code, but not necessarily as easy to understand... First bring together all the pieces we need:
An application to create a java interface from the wsdl (I cover here the use of WSDL2Java).
The SEI (Service Endpoint Interface) generated here by WSDL2Java.
A client class using the classes generated by WSDL2Java.
If you want to use WSDL2Java here are some tips: this tool comes with AXIS (Eclipse plugging), you will find it at: Ojectlearn. If you are using another IDE than Eclipse, do not worry and just uncompress the package downloaded and copy axis.jar (in /lib directory) in the appropriate location on your system. So your OS will find it at runtime. As soon as axis.jar is in your path, you can invoke the tool by the command line:
[your_prompt]$ java org.apache.axis.wsdl.WSDL2Java
For the Windows users: nothing change except your prompt:
C:\your_path>java org.apache.axis.wsdl.WSDL2Java
If all is working well then you can generate the classes by this command for my on-line document/literal web service (check here if on-line):
[your_prompt]$ java org.apache.axis.wsdl.WSDL2Java http://www.pascalbotte.be/rcx-ws/rcx?WSDL -Nhttp://phonedirlux.homeip.net/wsdl=rcxwsclient.sei -W
You can also test my rpc/encoded web service using the following command, see I omitted the -W option.
[your_prompt]$ java org.apache.axis.wsdl.WSDL2Java http://www.pascalbotte.be/rcx-ws-rpc/rcx?WSDL -Nhttp://phonedirlux.homeip.net/wsdl=rcxwsclient.sei
![]() | Important note for web service using operation style: document, use: literal WSDL |
|---|---|
For a WS-I, document/literal web service you must add the option -W when calling WSDL2Java. So if you want to consume another web service (rpc/encoded) do not use the option -W! |
I you don't know the type of the web service you want to consume (rpc/encoded or document/literal), you can use my WSDL parser (check my home page to see if on-line). Type the url pointing to the wsdl you want to parse and see the little report in human-readable format (free service).
Once you have the required files created on your local directory: take a look at the one you will need for this first demo (the service endpoint interface corresponding to the interface RcxReadLS, the portType name in the wsdl):
![]() | Mapping namespace to package |
|---|---|
If you didn't use the -N option you will have to manually copy the file RcxReadLS.java in the correct directory of your project (see below). |
your_local_directory/net/homeip/phonedirlux/wsdl/RcxReadLS.java (for Linux)
your_local_directory\net\homeip\phonedirlux\wsdl\RcxReadLS.java (for Windows)
The method String readLS(String string_1) (inside this interface) is supposed to return the value of the light sensor on the RCX. For this first test, you will get a fixed string (we will test later another method returning a live value of the light sensor in percent, you will then get an integer).
Here we will just use one method: String readLS(String string_1), it takes a string as param and return a string. To make this example more clear comment the methods we will not use and, if necessary (depending if you used the option -N or not), adapt the package name as shown in bold in Example 1-2. Make sure to copy this file to the appropriate directory of your project: directory_project/rcxwsclient/sei corresponding to the package name.
![]() | ![]() | ![]() |
| SOAP client for Java WSDP and .NET web service. | ![]() My home page Index RSS | First Java SOAP client (rpc/encoded or literal and document/literal in section 1.2.5) |