WEBSERVICE快速入门的示例:
首先定义接口:
- package?com.whaty.platform.ws.server;??
- ??
- import?javax.jws.WebService;??
- ?
- ?*?@className:IMyservice.java?
- ?*?@Desc:定义:SEI?service?endpoint?interface?
- ?*?@author:lizhuang?
- ?*?@createTime:2012-12-21?上午12:57:18?
- ?*/??
- //JAX-WS注解,表示java?api?xml?for?webservice。JDK自带API的XML格式的webservice??
- @WebService??
- public?interface?IMyservice?{??
- ??????
- ????int?add(int?a,?int?b);??
- int?minus(}??
其次编写实现类:
copy
?//endpointInterface指定接入点接口:接口必须存在??
@WebService(endpointInterface="com.whaty.platform.ws.server.IMyservice")??
class?MyServiceImpl?implements?IMyservice?{??
int?b)?{??
????????System.out.println("a+b="+(a+b));??
????????return?a+b;??
????}??
??
int?b)?{??
"a-b="+(a-b));??
return?a-b;??
????}??
最后发布我们的服务,直接右键运行main方法,如果控制台没报错,多半是发布成功了,否则检查你的代码:
浏览器地址栏输入:访问webservice看看是否发布成功【地址后面加上"?wsdl"】:
http://localhost:7777/tudou?wsdl
浏览器显示如下:
?
-->??
<!--?
?Generated?by?JAX-WS?RI?at?http://jax-ws.dev.java.net.?RI's?version?is?JAX-WS?RI?2.1.6?in?JDK?6.??
-->??
<definitions?xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"?xmlns:tns="http://server.ws.platform.whaty.com/"?xmlns:xsd="http://www.w3.org/2001/XMLSchema"?xmlns="http://schemas.xmlsoap.org/wsdl/"?targetNamespace="http://server.ws.platform.whaty.com/"?name="MyServiceImplService">??
types>??
xsd:schemaxsd:import?namespace="http://server.ws.platform.whaty.com/"?schemaLocation="http://localhost:7777/tudou?xsd=1"/>??
</message?name="minus"part?name="parameters"?element="tns:minus"message"minusResponse""tns:minusResponse"/>??
"add""tns:add""addResponse""tns:addResponse"portType?name="IMyservice"operation?name=input?message=output?message=operationportTypebinding?name="MyServiceImplPortBinding"?type="tns:IMyservice"soap:binding?transport="http://schemas.xmlsoap.org/soap/http"?style="document"soap:operation?soapAction=""inputsoap:body?use="literal"outputbindingservice?name=port?name="MyServiceImplPort"?binding="tns:MyServiceImplPortBinding"soap:address?location="http://localhost:7777/tudou"portservicedefinitions>??
下面我们创建客户端访问:
控制台打印如下:
a+b=5
a-b=-3
原文:http://blog.csdn.net/yaerfeng/article/details/8352307