jaxws

版权声明:分享知识是一种快乐,愿你我都能共同成长! https://blog.csdn.net/qidasheng2012/article/details/78177381

客户端:

package cn.itcast.webservice.jaxws.client;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import cn.itcast.webservice.jaxws.service.Exception_Exception;
import cn.itcast.webservice.jaxws.service.WeatherInterfaceImpl;
import cn.itcast.webservice.jaxws.service.WeatherInterfaceImplService;

/**
 * Description:使用service类编写天气查询客户端程序
 */
public class WeatherClient {

    public static void main(String[] args) throws Exception_Exception,
            MalformedURLException {

        // 创建一个服务视图的对象
        // wsdl地址
        //实际企业开发中将下边的地址配置在配置文件中
        URL wsdlUrl = new URL("http://127.0.0.1:12345/weather?wsdl");
        // 指定wsdl文档中服务视图的名称
        // 第一个参数:namespace
        // 第二个参数:服务视图的名称
        QName serviceName = new QName(
                "http://service.jaxws.webservice.itcast.cn/",
                "WeatherInterfaceImplService");

        // 第一个参数wsdlDocumentLocation:wsdl地扯
        // 第二个参数:服务视图名称
        Service service = Service.create(wsdlUrl, serviceName);

        // 通过服务视图创建portType的代理对象
        WeatherInterfaceImpl weatherInterfaceImplPort = service
                .getPort(WeatherInterfaceImpl.class);

        // 调用portType的方法
        String resultString = weatherInterfaceImplPort.queryWeather("北京");

        System.out.println("天气查询结果:" + resultString);
    }
}

猜你喜欢

转载自blog.csdn.net/qidasheng2012/article/details/78177381
今日推荐