標籤:
建立一個簡單的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、等
使用idea和wsdl產生java代碼