使用idea和wsdl生成java代码

  1. 建立一个简单的java helloworld项目java

选择next:web

选择java helloworld project next框架

填写project name finish测试

2.  建立好项目后 选择项目 右键->webservice->Generate code

生成代码配置,填写wsdl路径,包路径,webservice平台(这里我选择的是jax-ws jdk自带的webservice实现方式,不用再下载jar包)xml

这里我使用的wsdl,是一个天气预报的webservice:http://www.webservicex.com/globalweather.asmx?WSDL get

选择finish 等待片刻就可看见生成的代码了:webservice

3. 测试代码it

在Main Class中填写以下代码 io

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、等

相关文章
相关标签/搜索