package jsl.clients;
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;
import org.apache.axis.encoding.ser.ElementDeserializerFactory;
import org.apache.axis.encoding.ser.ElementSerializerFactory;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
public class WeatherClient3 {
private Call call = null;
private Message message = null;
private MessageContext msgCtxt = null;
public void process() {
//http://ws2.serviceobjects.net/fw/FastWeather.asmx?WSDl
String endpointUrl = "http://127.0.0.1:100/fw/FastWeather.asmx";
String namespaceUri = "http://www.serviceobjects.com/";
String serviceName = "http://www.serviceobjects.com/";
String operationName = "GetWeatherByZip";
try {
Service service = new Service();
call = (Call)service.createCall(); //returns javax.xml.rpc.Call
call.setTargetEndpointAddress(new java.net.URL(endpointUrl));
//call.setOperationName(new QName("http://www.myasptools.com/", "GetWeather"));
call.setOperationName(new QName(serviceName, operationName));
call.setOperationStyle("doc");
call.setSOAPActionURI("http://www.serviceobjects.com/GetWeatherByZip");
call.setUseSOAPAction(true);
// Set up serialization encoding for the Widget object
QName qname = new QName("http://www.serviceobjects.com/", "GetWeatherByZipResponse");
BeanSerializerFactory bsf = new BeanSerializerFactory(Weather.class, qname);
BeanDeserializerFactory bdf = new BeanDeserializerFactory(Weather.class, qname);
call.registerTypeMapping(Weather.class, qname, bsf, bdf);
//ElementSerializerFactory bsf = new ElementSerializerFactory();
//ElementDeserializerFactory bdf = new ElementDeserializerFactory();
//call.registerTypeMapping(Weather.class, qname, bsf, bdf);
call.addParameter("ns1:PostalCode", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter("ns1:LicenseKey", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter("GetWeatherByZipResponse", qname, Weather.class, javax.xml.rpc.ParameterMode.OUT);
call.setReturnType(qname, Weather.class);
//call.addParameter("GetWeatherByZipResponse", org.apache.axis.Constants.XSD_STRING, javax.xml.rpc.ParameterMode.OUT);
//call.setReturnType(org.apache.axis.Constants.XSD_STRING);
//String ret = (String)call.invoke(new Object[]{"Hello!"});
Object ret = call.invoke(new Object[] {"30330", "WS14-ELO4-IAD3"});
//setRequestResponse();
System.out.println("Got '" + ret + "'\nClass:" + ret.getClass().getName());
//System.err.println("\n\nREQUEST:");
//request.writeTo(System.err);
//System.err.println("\n\nRESPONSE:");
//response.writeTo(System.err);
} catch (Exception e) {
e.printStackTrace();
msgCtxt = MessageContext.getCurrentContext(); //ResponseMessage();
if (message != null) {
message = msgCtxt.getCurrentMessage();
}
System.err.println("message=" + message);
//System.err.println(e.toString());
}
}
public static void main(String[] args) {
WeatherClient3 wc = new WeatherClient3();
wc.process();
}
}
package jsl.clients;
public class Weather implements java.io.Serializable {
private long timeID;
private String lastUpdated;
private String time;
private String temperatureF;
private String windchill;
private String heatIndex;
private String humidity;
private String dewpoint;
private String wind;
private String pressure;
private String conditions;
private String visibility;
private String sunrise;
private String sunset;
private String city;
private String state;
private String moonrise;
private String moonset;
private String getWeatherByZipResponse;
public Weather() {
timeID = System.currentTimeMillis();
}
public void setGetWeatherByZipResponse(String s) {
getWeatherByZipResponse = s;
}
public String getGetWeatherByZipResponse() {
return getWeatherByZipResponse;
}
public String getCity() {
return city;
}
public String getConditions() {
return conditions;
}
public String getDewpoint() {
return dewpoint;
}
public String getHeatIndex() {
return heatIndex;
}
public String getHumidity() {
return humidity;
}
public String getLastUpdated() {
return lastUpdated;
}
public String getMoonset() {
return moonset;
}
public String getPressure() {
return pressure;
}
public String getState() {
return state;
}
public String getSunrise() {
return sunrise;
}
public String getSunset() {
return sunset;
}
public String getTemperatureF() {
return temperatureF;
}
public String getTime() {
return time;
}
public String getVisibility() {
return visibility;
}
public String getWind() {
return wind;
}
public String getWindchill() {
return windchill;
}
public void setCity(String city) {
this.city = city;
}
public void setConditions(String conditions) {
this.conditions = conditions;
}
public void setDewpoint(String dewpoint) {
this.dewpoint = dewpoint;
}
public void setHeatIndex(String heatIndex) {
this.heatIndex = heatIndex;
}
public void setHumidity(String humidity) {
this.humidity = humidity;
}
public void setLastUpdated(String lastUpdated) {
this.lastUpdated = lastUpdated;
}
public void setMoonrise(String moonrise) {
this.moonrise = moonrise;
}
public void setMoonset(String moonset) {
this.moonset = moonset;
}
public void setPressure(String pressure) {
this.pressure = pressure;
}
public void setState(String state) {
this.state = state;
}
public void setSunrise(String sunrise) {
this.sunrise = sunrise;
}
public void setSunset(String sunset) {
this.sunset = sunset;
}
public void setTemperatureF(String temp) {
temperatureF = temp;
}
public void setTime(String time) {
this.time = time;
}
public void setVisibility(String visibility) {
this.visibility = visibility;
}
public void setWind(String wind) {
this.wind = wind;
}
public void setWindchill(String windchill) {
this.windchill = windchill;
}
public String toString() {
return "" + timeID;
}
}
Server Response
/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Sun, 06 Apr 2003 23:04:26 GMT
Cache-Control: no-cache
Pragma: no-cache
Content-Type: text/xml; charset=utf-8
Content-Length: 857
<?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>
<GetWeatherByZipResponse xmlns="http://www.serviceobjects.com/">
<GetWeatherByZipResult>
<LastUpdated>6:53 PM EDT April 6, 2003</LastUpdated>
<TemperatureF>65</TemperatureF>
<Windchill>N/A</Windchill>
<HeatIndex>N/A</HeatIndex>
<Humidity>93%</Humidity>
<Dewpoint>63</Dewpoint>
<Wind>ENE at 10</Wind>
<Pressure>30.01</Pressure>
<Conditions>Thunderstorm Mist </Conditions>
<Visibility> 2</Visibility>
<Sunrise>07:16 AM (EDT)</Sunrise>
<Sunset>08:00 PM (EDT)</Sunset>
<City>Atlanta</City>
<State>Georgia</State>
<Moonrise>10:01 AM (EDT)</Moonrise>
<Moonset>12:42 AM (EDT)</Moonset>
</GetWeatherByZipResult>
</GetWeatherByZipResponse>
</soap:Body>
</soap:Envelope>
E>
SAXException
org.xml.sax.SAXException: Invalid element in jsl.clients.Weather - LastUpdated
at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeserializer.java:252)
at org.apache.axis.encoding.DeserializationContextImpl.startElement(DeAxisFault
faultCode: {http://xml.apache.org/axis/}Server.userException
faultString: org.xml.sax.SAXException: Invalid element in jsl.clients.Weather - LastUpdated
faultActor: null
faultDetail:
stackTrace: org.xml.sax.SAXException: Invalid element in jsl.clients.Weather - LastUpdated
at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeserializer.java:252)
at org.apache.axis.encoding.DeserializationContextImpl.startElement(DeserializationContextImpl.java:893)
at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:200)
at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:684)
......