使用idea和wsdl生成java代码

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

    120349_A4ln_872287.jpg

选择next:

120432_OXQ1_872287.jpg

选择java helloworld project next

120507_XXq5_872287.jpg

填写project name finish

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

120729_EP7d_872287.png

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

120905_V46Y_872287.png

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

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

121032_dJpR_872287.png

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

转载于:https://my.oschina.net/nba/blog/482117

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值