zoukankan      html  css  js  c++  java
  • WebService的使用

    1下载cxf及配置环境变量

    http://cxf.apache.org/download.html

    作为java常用工具,最好在环境变量里配置一下,另cxf-3.1.12需要jdk1.6以上
    在系统变量里的Path中添加(注意两个变量之间要有分号);D:apache-cxf-3.1.12in

    也可以不配

    cmd中输入wsdl2java -help输出一大堆

     

    证明配置成功

    2创建服务端

    从刚才下载的D:apache-cxf-3.1.12lib

     

    2.1创建一个classHelloWorld

    package com.qjc.webservice;
    
    import java.util.Date;
    
    import javax.jws.WebService;
    
    @WebService
    public class HelloWorld {
    
        public String sayHi(String name) {
            return name + " 您好!现在时间是:" + new Date();
        }
    
    }


    2.2创建
    暴露Web Service的函数 

    package com.qjc.webservice;
    import javax.xml.ws.Endpoint;
    public class ServiceMain {
        public static void main(String[] args) {
            // 调用Endpoint的publish方法发布webservice
            Endpoint.publish("http://100.0.1.248:8089/helloworld", new HelloWorld());
            System.out.println("Web Service暴露成功");
        }
    }


     2.3运行主函数暴露Web Service

    2.4检验是否暴露成功

    然后运行浏览器,输入:http://100.0.1.248:8089/helloworld?wsdl 查看结果,如果成功生成如下wsdl文档则表示Web Service暴露成功。

     

    3、创建客户端

     

    3.1dos窗口运行如下命令

    wsimport -s D:\WorkSpace\nenoWorkSpace\TestWebServiceClient\src -p com.qjc.webservice -keep http://100.0.1.248:8089/helloworld?wsdl

     

    刷新项目

     

    3.2创建测试类

     

    package com.qjc.test;
    
    import com.qjc.webservice.HelloWorld;
    import com.qjc.webservice.HelloWorldService;
    
    public class ServiceTest {
    
        public static void main(String[] args) {
            HelloWorld helloWorldService = new HelloWorldService().getHelloWorldPort();
            String sayHi = helloWorldService.sayHi("乔家成");
            System.out.println(sayHi);
        }
    }

     运行如下:

  • 相关阅读:
    HTML -- Note
    JavaScript使用childNodes和children
    Qt编写自定义控件69-代码行数统计
    Qt编写自定义控件68-IP地址输入框
    Qt编写自定义控件67-通用无边框
    Qt编写自定义控件66-光晕时钟
    Qt编写自定义控件65-光晕日历
    Qt编写自定义控件64-垂直时间轴
    Qt编写自定义控件63-水波效果
    Qt编写自定义控件62-探探雷达
  • 原文地址:https://www.cnblogs.com/java-spring/p/7792938.html
Copyright © 2011-2022 走看看