package sample.pojo.data;
<o:p> </o:p>
public class Weather {
float temperature;
String forecast;
boolean rain;
float howMuchRain;
<o:p> </o:p>
public void setTemperature(float temp) {
temperature = temp;
}
<o:p> </o:p>
public float getTemperature() {
return temperature;
}
<o:p> </o:p>
public void setForecast(String fore) {
forecast = fore;
}
<o:p> </o:p>
public String getForecast() {
return forecast;
}
<o:p> </o:p>
public void setRain(boolean r) {
rain = r;
}
<o:p> </o:p>
public boolean getRain() {
return rain;
}
<o:p> </o:p>
public void setHowMuchRain(float howMuch) {
howMuchRain = howMuch;
}
<o:p> </o:p>
public float getHowMuchRain() {
return howMuchRain;
}
}
|
package sample.pojo.service;
<o:p> </o:p>
import sample.pojo.data.Weather;
<o:p> </o:p>
public class WeatherService{
Weather weather;
public void setWeather(Weather weather){
this.weather = weather;
}
<o:p> </o:p>
public Weather getWeather(){
return this.weather;
}
}
|
<service scope="application" name="WeatherService"></service>
<description>Weather POJO Service</description>
<messagereceivers></messagereceivers>
<messagereceiver></messagereceiver>
mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
<messagereceiver></messagereceiver>
mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
<parameter name="ServiceClass"></parameter>
sample.pojo.service.WeatherService
|
- WeatherService<o:p></o:p>
- META-INF<o:p></o:p>
- services.xml<o:p></o:p>
- sample<o:p></o:p>
- pojo<o:p></o:p>
- data<o:p></o:p>
- Weather.class<o:p></o:p>
- service<o:p></o:p>
- WeatherService.class
|
package sample.pojo.rpcclient;
<o:p> </o:p>
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;<o:p></o:p>
import org.apache.axis2.rpc.client.RPCServiceClient;
import sample.pojo.data.Weather;
<o:p> </o:p>
public class WeatherRPCClient {
public static void main(String[] args1) throws AxisFault {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(
"http://localhost:8080/axis2/services/WeatherService");
options.setTo(targetEPR);
<o:p> </o:p>
// Setting the weather
QName opSetWeather = new QName("http://service.pojo.sample/xsd",
"setWeather");
Weather w = new Weather();
w.setTemperature((float) 39.3);
w.setForecast("Cloudy with showers");
w.setRain(true);
w.setHowMuchRain((float) 4.5);
<o:p> </o:p>
Object[] opSetWeatherArgs = new Object[] { w };
serviceClient.invokeRobust(opSetWeather, opSetWeatherArgs);
serviceClient.invokeRobust(opSetWeather, opSetWeatherArgs);
<o:p> </o:p>
// Getting the weather
QName opGetWeather = new QName("http://service.pojo.sample/xsd",
"getWeather");
<o:p> </o:p>
Object[] opGetWeatherArgs = new Object[] {};
Class[] returnTypes = new Class[] { Weather.class };
Object[] response = serviceClient.invokeBlocking(opGetWeather,
opGetWeatherArgs, returnTypes);
<o:p> </o:p>
Weather result = (Weather) response[0];
if (result == null) {
System.out.println("Weather didn't initialize!");
return;
}
<o:p> </o:p>
// Displaying the result
System.out.println("Temperature : "
+ result.getTemperature());
System.out.println("Forecast : "
+ result.getForecast());
System.out.println("Rain : " + result.getRain());
System.out.println("How much rain (in inches) : "
+ result.getHowMuchRain());
<o:p> </o:p>
}
}
|
Temperature : 39.3
Forecast : Cloudy with showers
Rain : true
How much rain (in inches) : 4.5
|
本文出自 “子 孑” 博客,请务必保留此出处http://zhangjunhd.blog.51cto.com/113473/26053