JAVA Webservice 服务端 简单时间接口实例

1.建立一个 Dynamic Web Project 项目,名称: DSFASTEST
新建com.enfo.intrust.wd Package包
2.创建TimeServer接口

package com.enfo.intrust.wd;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public interface TimeServer {
	@WebMethod String getTimeAsString();
    @WebMethod long getTimeAsElapsed();
}

3.创建TimeServerImpl继承接口TimeServer

package com.enfo.intrust.wd;

import java.util.Date;

import javax.jws.WebService;
@WebService(endpointInterface = "com.enfo.intrust.wd.TimeServer")
public class TimeServerImpl implements TimeServer {

	   public String getTimeAsString() {   
		   return new Date().toString(); 
	   }
	   
	   public long getTimeAsElapsed() {
		   return new Date().getTime();
	   }

}

4.TimeServerPublisher测试类

package com.enfo.intrust.wd;

import javax.xml.ws.Endpoint;

import com.enfo.intrust.webservice.WebServiceImpl;

public class TimeServerPublisher {

	public static void main(String[] args) {
		 String address = "http://128.8.18.152:8080/DSFASTEST/TimeServer";
		 try {
			Endpoint.publish(address, new TimeServerImpl());
			System.out.println("webService成功");
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

	}

}

结果
JAVA Webservice 服务端 简单时间接口实例_第1张图片

你可能感兴趣的:(JAVA Webservice 服务端 简单时间接口实例)