This page walks you through the creation of a Web Service client from a URL pointer.


This tutorial is based on the location service WSDL, and shows the flow of creating a Web Service client from the WSDL file. As a prerequisite we assume that you are familiar with Java programming, and understand Web Services, and have registered your MSDN number.



1. After downloading and installing the tools correctly, start the Eclipse tool.
2. Create a new Java project. Select "File -> New -> Java Project" from the toolbar, and the "New Java Project" wizard starts.

new project
3. Give the project a name, and choose your preferences on Java version and project organization. In this example the project is called "Get Location demo Client", The default values are used for all other selections in this example.
4. Push "Finish" to continue and close the wizard. The project is created, and you can continue to start adding content to your project.
5. Select your project, push the right mouse button and then select "New -> Other" on the toolbar, to start the New wizard.
WebService Wizard step 1
6. Select Web Service Client from the New menu, and push the "Next" button. The Web Service Client wizard starts. Here you choose the Web Service location (WSDL file) that we are creating a client for, and the type of client (Java proxy).
WebService Wizard step 2
7. Push the "Browse" button and the Select Service Implementation wizard starts.
Select Service Implementation
8. Type in the address to the WSDL file, which in this example is http://px.pats.no/px/services/TerminalLocation?wsdl The tool validates the WSDL file, when the address is fully entered. The current version of WSDL file and validation tool shows a warning message. Push "OK" to return to the Web Service Client wizard.
WebService Wizard step 2
9. Slide the slider down to only create a client, and push the "Finish" button. The tool creates the stubs and skeletons required to invoke the service.
The next step is to create the code that invokes the service.
10. Add a new Java class, containing a main method. Select your project, and then select "New -> Java" class on the toolbar, to start the New Java Class wizard.
New Java Class
Name the Java class, in this example "MyLocation" and check to "generate main method". Click on "Finish" and the classes are generated.
NB: In order to avoid some warning messages from the run-time system, you can add activation.jar and mail.jar to the build path. They are not required for this tutorial, but you might want to know why they appear. Click on the jar names to download the files. Use right mouse button on the project, and select Properties. Push the Add External JAR's button, to select the JAR files. Push OK, when you are done.
Project properties
11. Finally you need to add your code from the example page, or load the code from here or cut & paste from code box below.
import java.rmi.RemoteException;
import java.util.Calendar;
import javax.xml.rpc.ServiceException;
import org.apache.axis.types.URI.MalformedURIException;
import org.csapi.www.schema.parlayx.common.v2_1.PolicyException;
import org.csapi.www.schema.parlayx.terminal_location.v2_2.LocationInfo;
import org.csapi.www.wsdl.parlayx.terminal_location.v3_0.service.TerminalLocation;
import org.csapi.www.wsdl.parlayx.terminal_location.v3_0.service.TerminalLocationServiceLocator;

public class MyLocation {
	MyLocation(){
		try {
			TerminalLocation tls = new TerminalLocationServiceLocator().getTerminalLocation();
			// Set username and password
			String userName = "xxxxxxx";
			String passWord = userName;
			org.apache.axis.client.Stub stub = (org.apache.axis.client.Stub)tls; 
			stub.setUsername(userName);
			stub.setPassword(passWord);
			// Invoke service
			org.apache.axis.types.URI address = new org.apache.axis.types.URI("tel", "yyyyyyyy");
			org.apache.axis.types.URI requester = new org.apache.axis.types.URI("tel", "2034");
			LocationInfo li = tls.getLocation(requester,address,1,1,null,null,null); 
			if(li != null){
				float lat = li.getLatitude();
				float lon = li.getLongitude();
				Calendar when = li.getTimestamp();
				System.out.println("Terminal: " + address.getSchemeSpecificPart() + " is at: (lat)" + lat + " (lon)" + lon + " " + when.getTime());
			}	
			else System.out.println("Could not obtain location");
		} catch (ServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (PolicyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURIException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new MyLocation();
	}
}
Your project should then look like this, and be able to compile and run. Note that you must add your MSDN number 8 digits, without country code, as username and password in your code. This is the MSDN number you used when you signed up for the demo service.
12. Compile and run inside Eclipse
Final
13. Or run from a console window like this:
Console
Copyright Telenor R&I 2007