webservice
Java 中的 Web Service 分为基于 SOAP 的和基于 REST 的两种,下面简单说一个基于 SOAP 的例子。要使用 JDK6u4?之后的版本才能编译通过。 先编写一个 Web Service 的接口: package com; import javax.jws.WebMethod; import javax.jws.WebService; @WebService public interface TimeServer { ? ? @WebMethod String getTimeAsString(); ? ? @WebMethod long getTimeAsElapsed();? } package com; import java.util.Date; import javax.jws.WebService; @WebService(endpointInterface = "com.TimeServer") public class TimeServerImpl implements TimeServer { ? ? public String getTimeAsString() { return new Date().toString(); } ? ? public long getTimeAsElapsed() { return new Date().getTime(); } } package com; import javax.xml.ws.Endpoint; ? public class TimeServerPublisher { ? ? public static void main(String[ ] args) { ? ? TimeServerImpl tt= new TimeServerImpl(); ? ? ? Endpoint.publish("http://127.0.0.1:9876/ts",tt ); ? ? } } 如果正常启动,可以用浏览器访问?http://127.0.0.1:9876/ts?wsdl?看到这个 Web Service 的 wsdl 文档。 转载http://zhidao.baidu.com/link?url=8QY81dR99QHJn1eNtOkMswopFR122Sl9IJg9s8c_r5h7M2-xtCrHed3ldJdV-NvSZu9ESSAV0sPX_hicxgmbDJOE6WinI9brpHRZPwFeFHe (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |