/* TempConversionClient.java by Jeffrey K. Brown TempConversionClient.java is a Crude Example of how to call a Web Service method. You'll notice the difference between the way we link to and call the TemperatureConversion methods versus the WSDL2Java-generated methods. Basically, in this TempConversionClient, we have to manually set up a lot of the things that the WSDL2Java does for us, basically eliminating a few different steps and replacing them with two. */ import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; import org.apache.axis.utils.Options; import javax.xml.rpc.ParameterMode; import java.net.*; public class TempConversionClient { public static void main (String[] args) throws Exception { double temperature = 212.0; String endpoint = "http://viper.transpro.com:8180/axis/TemperatureConversion.jws"; //String endpoint = "http://localhost:8180/axis/TemperatureConversion.jws"; // First we set up a service object. Service service=null; try { service = new Service(); } catch (Exception e) { System.out.println("Service Initialization Error"); e.printStackTrace(); } // Next, we set up a function call to that service. Call call=null; try { call = (Call) service.createCall(); } catch (Exception e) { System.out.println("Call Initialization Error"); e.printStackTrace(); } // Then, we point the service call at the server and application // running the service. try { call.setTargetEndpointAddress(new URL(endpoint)); } catch (Exception e) { System.out.println("Error Setting Target Endpoint"); e.printStackTrace(); } // Now we set up the method name, in this case c2f, the Celcius to Fahrenheit try { call.setOperationName("c2f"); } catch (Exception e) { System.out.println("Error setting Operation!"); e.printStackTrace(); } // The temperature parameter we are sending back must be in the right format, // so we explicitly declare that it is an XML-compatible Double. try { call.addParameter("temp", XMLType.XSD_DOUBLE, ParameterMode.IN); } catch (Exception e) { System.out.println("Error Adding Parameter"); e.printStackTrace(); } // Then, we specify in this application how we want the result back, I'm not sure // if it casts the result in the XML, but I wanted a String back instead of a double // because I was experimenting on something, but I forget exactly what. try { //call.setReturnType(XMLType.XSD_DOUBLE); call.setReturnType(XMLType.XSD_STRING); } catch (Exception e) { System.out.println("Error Setting Return Type"); e.printStackTrace(); } System.out.println(""+ temperature + " Degrees F = "); // Now we actually call the method passing the array of parameters to the web service. // Once received, we print it. try { String ret = (String) call.invoke (new Object [] { temperature }); System.out.println(ret); } catch (Exception e) { System.out.println("Error Retreiving Return Value"); e.printStackTrace(); } System.out.println("Degrees C"); } }