创建简单的web service服务

  1. 定义WebServiceI接口
package com.ljl.test.wbs;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface WebServiceI {

    @WebMethod
    String sayHello(String name);

    @WebMethod
    String save(String name, String pwd);

}
  1. WebServiceI接口实现类WebServiceImpl
package com.ljl.test.wbs;

import javax.jws.WebService;

@WebService
public class WebServiceImpl implements WebServiceI {
    @Override
    public String sayHello(String name) {
        System.out.println("WebService sayHello "+name);
        return "sayHello "+name;
    }

    @Override
    public String save(String name, String pwd) {
        System.out.println("WebService save "+name+", "+pwd);
        return "save success";
    }
}
  1. 发布WebService服务
package com.ljl.test;

import com.ljl.test.wbs.WebServiceImpl;

import javax.xml.ws.Endpoint;

/**
 * Hello world!
 *
 */
public class WebServicePublish
{
    public static void main( String[] args )
    {
        String address = "http://192.168.1.102:8989/WS_Server/Webservice";
        Endpoint.publish(address, new WebServiceImpl());
        System.out.println( "Hello World!" );
    }
}

运行后结果如下:
创建简单的web service服务_第1张图片

你可能感兴趣的:(web,service)