Our small user group is trying to learn how to use web services and we picked a small project to start with. We want to write a client that gets data from an existing web service and then write our own server that mimics the existing service.
I'm trying to write client code to use the GetWeatherReport service from http://www.webservicex.net/usweather.asmx , but I am not getting any data in the return. I get the SOAP reply, but the return string only has the tags, no values. When I submit the zipcode via the webpage I do get weather data. It appears that the service is not recognizing the input variable ZipCode because if I name it to something else (like ZipCode2) I get the same result. I am including the java class and the capture of the request and response. import java.net.URL; import javax.xml.namespace.QName; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.ser.BeanDeserializer; import org.apache.axis.encoding.ser.BeanDeserializerFactory; import org.apache.axis.encoding.ser.BeanSerializer; import org.apache.axis.encoding.ser.BeanSerializerFactory; public class WeatherClient2 { private Call call = null; public void process() { String endpointUrl = "http://www.webservicex.net/usweather.asmx String namespaceUri = "http://www.webserviceX.NET/"; String serviceName = "http://www.webserviceX.NET/"; String operationName = "GetWeatherReport"; try { Service service = new Service(); call = (Call)service.createCall(); //returns javax.xml.rpc.Call call.setSOAPVersion(new org.apache.axis.soap.SOAP11Constants()); call.setTargetEndpointAddress(new java.net.URL(endpointUrl)); call.setOperationName(new QName(serviceName, operationName)); call.setOperationStyle("rpc"); call.setSOAPActionURI("http://www.webserviceX.NET/GetWeatherReport"); call.setUseSOAPAction(true); //QName USZip = new QName("http://www.webserviceX.NET", "USZip"); //call.addParameter("ns1:zipCode", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN); //call.setReturnType(org.apache.axis.Constants.XSD_ANYTYPE ,java.lang.String.class); // Set up serialization encoding for the Widget object QName qname = new QName(namespaceUri, "Weather"); //call.registerTypeMapping(Weather.class, qname, // new BeanSerializerFactory( Weather.class, qname ), // new BeanDeserializerFactory( Weather.class, qname ) ); call.addParameter("ns1:ZipCode", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN); //call.addParameter( "GetWeatherReportResult", qname, javax.xml.rpc.ParameterMode.OUT); //call.setReturnType(qname); call.setReturnType(org.apache.axis.Constants.XSD_STRING); Object ret = call.invoke(new Object[] {"30297"}); System.out.println("Got '" + ret + "'"); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { WeatherClient2 wc = new WeatherClient2(); wc.process(); } } ==== Request ==== POST /usweather.asmx HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1.0 Host: www.webservicex.net Cache-Control: no-cache Pragma: no-cache SOAPAction: "http://www.webserviceX.NET/GetWeatherReport" Content-Length: 482 <?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <ns1:GetWeatherReport soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.webserviceX.NET/"> <ns1:ZipCode xsi:type="xsd:string">30297</ns1:ZipCode> </ns1:GetWeatherReport> </soapenv:Body> </soapenv:Envelope> ==== Response ==== HTTP/1.1 200 OK Server: Microsoft-IIS/5.0 Date: Sat, 05 Apr 2003 19:09:29 GMT Cache-Control: private, max-age=0 Content-Type: text/xml; charset=utf-8 Content-Length: 1846 <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetWeatherReportResponse xmlns="http://www.webserviceX.NET"> <GetWeatherReportResult><Weather><City></City><State> ;</State><County></County><Fahrenheit></Fahrenhei t><Celsius></Celsius><Condition></Condition><H umidity></Humidity><Wind></Wind><Sunrise></Sun rise><Sunset></Sunset><DailyReport><Day></Day& gt;<HighFahrenheit></HighFahrenheit><HighCelsius></High Celsius><LowFahrenheit></LowFahrenheit><LowCelsius>< /LowCelsius></DailyReport><DailyReport><Day></Day> ;<HighFahrenheit></HighFahrenheit><HighCelsius></HighCe lsius><LowFahrenheit></LowFahrenheit><LowCelsius></L owCelsius></DailyReport><DailyReport><Day></Day>& lt;HighFahrenheit></HighFahrenheit><HighCelsius></HighCels ius><LowFahrenheit></LowFahrenheit><LowCelsius></Low Celsius></DailyReport><DailyReport><Day></Day>< ;HighFahrenheit></HighFahrenheit><HighCelsius></HighCelsiu s><LowFahrenheit></LowFahrenheit><LowCelsius></LowCe lsius></DailyReport><DailyReport><Day></Day><H ighFahrenheit></HighFahrenheit><HighCelsius></HighCelsius& gt;<LowFahrenheit></LowFahrenheit><LowCelsius></LowCels ius></DailyReport></Weather></GetWeatherReportResult> </GetWeatherReportResponse> </soap:Body> </soap:Envelope>