首页 > 技术文章 > jdk自带发布webservice服务

suncj 2014-10-09 14:00 原文

1.创建要发布的类

package com.test.webserive;

import javax.jws.WebService;
//targetNamespace定义命名空间
@WebService(targetNamespace="http://www.mess.com")
public class HelloServiceImpl {

    public String sayHello(String name){
        return "Hello:"+name;
    }

    public String syaHi(String username){
        return "Hi:"+username;
    }

}

2.发布服务

package com.test.webserive;

import javax.xml.ws.Endpoint;


public class Service {

    public static void main(String[] args){
        /**
         * 参数1:服务器的发布地址
         * 参数2:服务的实现者
         */
        Endpoint.publish("http://10.90.2.17:6789/hello", new HelloServiceImpl());
        System.out.println("Server ready...");

    }

}

3.启动运行,打开浏览器输入

http://10.90.2.17:6789/hello?wsdl
看到下面文件即成功发布:

 

 


推荐阅读