标签:
创建一个简单的java helloworld项目
选择next:
选择java helloworld project next
填写project name finish
2. 创建好项目后 选择项目 右键->webservice->Generate
生成代码配置,填写wsdl路径,包路径,webservice平台(这里我选择的是jax-ws jdk自带的webservice实现方式,不用再下载jar包)
这里我使用的wsdl,是一个天气预报的webservice:http://www.webservicex.com/globalweather.asmx?WSDL
选择finish 等待片刻就可看见生成的代码了:
3. 测试代码
在Main Class中填写如下代码
import weather.GlobalWeather; import weather.GlobalWeatherSoap; public class Main { public static void main(String[] args) { GlobalWeather service = new GlobalWeather(); GlobalWeatherSoap port = service.getGlobalWeatherSoap(); String body = port.getWeather("shanghai", "China"); System.out.println(body); } }
运行结果如下:
<?xml version="1.0" encoding="utf-16"?> <CurrentWeather> <Location>Shanghai / Hongqiao, China (ZSSS) 31-10N 121-26E 3M</Location> <Time>Jul 22, 2015 - 12:00 AM EDT / 2015.07.22 0400 UTC</Time> <Wind> Variable at 2 MPH (2 KT):0</Wind> <Visibility> greater than 7 mile(s):0</Visibility> <SkyConditions> mostly clear</SkyConditions> <Temperature> 84 F (29 C)</Temperature> <DewPoint> 78 F (26 C)</DewPoint> <RelativeHumidity> 83%</RelativeHumidity> <Pressure> 29.65 in. Hg (1004 hPa)</Pressure> <Status>Success</Status> </CurrentWeather>
生成代码的平台框架,也可以选择axis 、cxf、等
标签:
原文地址:http://my.oschina.net/nba/blog/482117