Java6开辟WebService入门[Java编程]
本文“Java6开辟WebService入门[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
之前常常用CXF、Axis2、XFire等来开辟结合Java语言来开辟Web Service利用,这样的好处是用处广,机动,别的一个重要缘由是我们的生产环境是Java5.
但实际上Java6中已经支持用Java开辟WebService利用了,并且很便利.这样就大大削减了项目安装布置的代价,因为挑选开源的框架依靠大量第三方包,程序的尺寸倍增.
下面是一个Java6开辟Web Service的入门例子.
package lavasoft;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
/**
* Java6开辟WebService入门
*
* @author leizhimin 2009-11-13 16:10:44
*/
@WebService
public class Java6WebService {
/**
* Web服务中的业务办法
*
* @return 一个字符串
*/
public String doSomething() {
return "Hello Java6 WebService!";
}
public static void main(String[] args) {
//公布一个WebService
Endpoint.publish("http://192.168.14.117:8080/java6ws/lavasoft.Java6WebService", new Java6WebService());
}
}
运行后,在浏览器中拜候http://192.168.14.117:8080/java6ws/lavasoft.Java6WebService?wsdl会得到wsdl 以下:
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.
-->
<!-- 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://lavasoft/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://lavasoft/" name="Java6WebServiceService">
<types>
<xsd:schema>
<xsd:import namespace="http://lavasoft/"
schemaLocation="http://192.168.14.117:8080/java6ws/lavasoft.Java6WebService?xsd=1"/>
</xsd:schema>
</types>
<message name="doSomething">
<part name="parameters" element="tns:doSomething"/>
</message>
<message name="doSomethingResponse">
<part name="parameters" element="tns:doSomethingResponse"/>
</message>
<portType name="Java6WebService">
<operation name="doSomething">
<input message="tns:doSomething"/>
<output message="tns:doSomethingResponse"/>
</operation>
</portType>
<binding name="Java6WebServicePortBinding" type="tns:Java6WebService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="doSomething">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="Java6WebServiceService">
<port name="Java6WebServicePort" binding="tns:Java6WebServicePortBinding">
<soap:address location="http://192.168.14.117:8080/java6ws/lavasoft.Java6WebService"/>
</port>
</service>
</definitions>
以上是“Java6开辟WebService入门[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |