package webservice;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
@WebService
public class TestWebservice {
public String getValue(String name){
return "my name is :"+name;
}
public static void main(String[] args) {
Endpoint.publish("http://localhost:9001/test/TestWebservice", new TestWebservice());
System.out.println("webservice success!");
}
}
直接把代码copy到myeclipse运行就可以了,启动后,在浏览器访问:
http://localhost:9001/test/TestWebservice?wsdl
效果如下
<definitions targetNamespace="http://webservice/" name="TestWebserviceService"><types><xsd:schema>
<xsd:import namespace="http://webservice/" schemaLocation="http://localhost:9001/test/TestWebservice?xsd=1"/>
</xsd:schema></types><message name="getValue"><part name="parameters" element="tns:getValue"/></message>
<message name="getValueResponse"><part name="parameters" element="tns:getValueResponse"/></message>
<portType name="TestWebservice"><operation name="getValue"><input message="tns:getValue"/><output message="tns:getValueResponse"/>
</operation></portType><binding name="TestWebservicePortBinding" type="tns:TestWebservice">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getValue"><soap:operation soapAction=""/><input><soap:body use="literal"/></input><output><soap:body use="literal"/>
</output></operation></binding><service name="TestWebserviceService"><port name="TestWebservicePort" binding="tns:TestWebservicePortBinding">
<soap:address location="http://localhost:9001/test/TestWebservice"/></port></service></definitions>
本文介绍了一个简单的 Java WebService 实现方法,通过使用 JAX-WS 和相关注解快速搭建了一个能够响应请求的服务端点。该 WebService 提供了一个名为 getValue 的操作,返回带有输入名字的字符串。
145

被折叠的 条评论
为什么被折叠?



