webService学习(一)—— hello world

来源:互联网 发布:冬不拉教程软件 编辑:程序博客网 时间:2024/06/05 17:07

webService学习(一)—— hello world

下面介绍一个简答的webService,同时包含调用过程。
1、首先新建一个项目:
修改代码:
package com.xueyoucto.xueyou;import javax.jws.WebService;import javax.xml.ws.Endpoint;/** * Created by Administrator on 2017/1/14. */@WebServicepublic class HelloService {    public String testService(String params){        return "hello " + params;    }    public static void main(String[] args) {        Endpoint.publish("http://localhost:8888/HelloService/",new HelloService());        System.out.println("ok");    }}

2、运行项目,运行后控制台输出:


3、查看webservice状态:


3、新建一个项目,然后把webService以接口和配置文件的方式导入到项目中:

4、查看项目中新增的内容:


5、编写程序调用webService(这里采用直接接口调用的方式)
package com.tt;import com.otherWebService.HelloService;import com.otherWebService.HelloServiceService;/** * Hello world! * */public class App {    public static void main( String[] args ) {        System.out.println( "Hello World!" );        HelloService helloService = new HelloServiceService().getHelloServicePort();        String s  = helloService.testService("aabbcc");        System.out.println(s);    }}

6、运行结果:


7、注意,在重复进行webService的运行时,会出现端口占中,这时可以使用如下命令:
netstat -ano | findstr "8888"


在任务管理器中根据PID进行进程的终止。


0 0
原创粉丝点击