|
|
问题描述:
webservice定义如下:
public void setWeather(@WebParam(name = "weather") Weather weather,@WebParam(name = "city") String city,@WebParam(name = "country") String country) {System.out.println("weather:" + weather);System.out.println("city:" + city);System.out.println("country:" + country);this.weather = weather;}
使用wsdl2java生成client,调用时,缺少第二个参数:
WeatherServiceStub.SetWeather setWeather = new SetWeather();WeatherServiceStub.Weather weather = new Weather();weather.setTemperature(20.3f);weather.setHowMuchRain(102.3f);weather.setRain(true);weather.setForecast("rain");setWeather.setWeather(weather);setWeather.setCountry("china");WeatherServiceStub stub = new WeatherServiceStub("http://localhost:8080/axis2/services/WeatherService");stub.setWeather(setWeather); 此请求发送到客户端的soap 消息为:
<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><ns2:setWeather xmlns:ns2="http://service.pojo.sample"><ns2:weather><ns1:forecast xmlns:ns1="http://data.pojo.sample/xsd">rain</ns1:forecast><ns1:howMuchRain xmlns:ns1="http://data.pojo.sample/xsd">102.3</ns1:howMuchRain><ns1:rain xmlns:ns1="http://data.pojo.sample/xsd">true</ns1:rain><ns1:temperature xmlns:ns1="http://data.pojo.sample/xsd">20.3</ns1:temperature></ns2:weather><ns2:country>china</ns2:country></ns2:setWeather></soapenv:Body></soapenv:Envelope>
soap消息中没有city节点,服务端打印:
weather:Weather [temperature=20.3, forecast=rain, rain=true, howMuchRain=102.3]city:chinacountry:null
解析参数顺序出错。
--------------------------------------------------------------------------------------------------------
解决办法:
出现这个问题的原因是使用ant编译后的class,默认不会保留调试相关信息,而axis2正是使用vars信息来正确绑定参数,所以只要在编译类文件时保留这些信息就可以了。
在ant脚本中启用debug,他会保留vars,参考http://ant.apache.org/manual/Tasks/javac.html
<javac srcdir="src" debug="true" debuglevel="vars"destdir="${dest.dir.classes}"includes="sample/pojo/service/**,sample/pojo/data/**">
<classpath refid="build.class.path" />
</javac>
|
|