请问JSE1.6怎么实现webservice服务端 最近做完一个项目用的是JSE1.6,需要提供接口供主控计算机控制访问(用的是webservice),请问我如何在java工程里编程,才能让客户端访问我这里的应用程序,请说明的详细一些,本人对J2SE和web开发都不太懂,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://topic.csdn.net/u/20080425/00/33A47C75-07D4-49E0-9628-BE23554AB142.html webservice应该是属于j2ee的内容吧,需要web容易的支持。 需要按照webservice方式写java程序。并需要发布到你们的系统(应该是个web应用)中。这样你只要告诉客户的方法以及参数,你的客户就可以在他们自己的程序中使用你提供的功能。至于如何用webservice方式写java程序并发布,需要参考一些资料。 利用cxf开发WebService(转载) http://www.cnblogs.com/orchidsure/archive/2009/05/12/1455089.html package hello;import javax.jws.WebService;import javax.xml.ws.Endpoint;@WebServicepublic class CircleFunctions { public double getArea(double r) { System.out.println("Hello Web Service"); return java.lang.Math.PI * (r * r); } public double getCircumference(double r) { return 2 * java.lang.Math.PI * r; } public static void main(String[] args) { Endpoint.publish( "http://localhost:9800/WebServiceExample/circlefunctions", new CircleFunctions()); }}client sidepackage hello.client;public class Client { public static void main(String[] args) { try { hello.client.jaxws.CircleFunctionsService service = new hello.client.jaxws.CircleFunctionsService(); hello.client.jaxws.CircleFunctions port = service.getCircleFunctionsPort(); double arg0 = 3.0; double result = port.getArea(arg0); System.out.println("Result = "+result); } catch (Exception ex) { ex.printStackTrace(); } }}xml build file:<project name="webservice.example" default="compilesrc" basedir="."> <property file="build.properties" /> <property name="sourcedir" value="${basedir}/src" /> <property name="testscrdir" value="${basedir}/dev/test" /> <property name="targetdir" value="${basedir}/target" /> <property name="buildclass" value="${targetdir}" /> <target name="clean"> <delete dir="${buildclass}" /> <delete dir="${targetdir}" /> </target> <target name="compilesrc" depends="clean" > <echo level="info" message="compile source code classes" /> <mkdir dir="${buildclass}" /> <javac debug="true" srcdir="${sourcedir}" destdir="${buildclass}" classpathref="libraries" /> </target> <target name="copy-resources"> <copy todir="${targetdir}"> <fileset dir="${sourcedir}"> <exclude name="**/*.java" /> </fileset> </copy> </target> <path id="jaxws.classpath"> <fileset dir="${jaxws.home}/jaxws_lib"> <include name="**/*.jar" /> </fileset> </path> <path id="libraries"> <pathelement path="${buildclass}" /> <path refid="jaxws.classpath"/> </path> <!-- Define the Jax WS ant tasks --> <taskdef name="Apt" classname="com.sun.tools.ws.ant.Apt"> <classpath refid="libraries"/> </taskdef> <!-- Define the Jax WS ant tasks --> <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport"> <classpath refid="libraries"/> </taskdef> <taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen"> <classpath refid="libraries"/> </taskdef> <target name="genwsartifacts"> <wsgen sei="hello.CircleFunctions" destdir="target" resourcedestdir="config" sourcedestdir="src" keep="true" verbose="true" genwsdl="true" fork="true"> <classpath refid="libraries" /> </wsgen> <wsimport debug="true" verbose="true" keep="true" destdir="target" sourcedestdir="src" package="hello.client.jaxws" wsdl="config/CircleFunctionsService.wsdl"> </wsimport> </target> <target name="postprocess" description="Post process the wsdl and the schema files" depends="genwsartifacts"> <!-- Replace the URL token --> <replace file="config/CircleFunctionsService.wsdl" token="REPLACE_WITH_ACTUAL_URL" value="${soap.address}"/> <replace file="config/CircleFunctionsService_schema1.xsd" token="minOccurs="0""/> </target></project> 另外你可以使用spring的standalone 的 web service component 本质上来说,任何在J2EE中应用的组件,都可以被移植到J2SE上 JTable单元格编辑失败还原 如何设计类的方法 初学JAVA者来请教 多线程Join()方法,高手请进 一个关于JToolBar的巨奇怪的问题,请求帮助! 菜鸟求助 关于闪烁 huangyan229 () 请进来取分。 紧急求助!! 那位高人知道怎样在VSS 5.0中建立数据库? 根据URL下载网页源代码 什么是桥方法啊 循环打印空心菱形,三个循环。
这样你只要告诉客户的方法以及参数,你的客户就可以在他们自己的程序中使用你提供的功能。至于如何用webservice方式写java程序并发布,需要参考一些资料。
import javax.jws.WebService;
import javax.xml.ws.Endpoint;@WebServicepublic class CircleFunctions {
public double getArea(double r) {
System.out.println("Hello Web Service");
return java.lang.Math.PI * (r * r);
} public double getCircumference(double r) {
return 2 * java.lang.Math.PI * r;
}
public static void main(String[] args) { Endpoint.publish(
"http://localhost:9800/WebServiceExample/circlefunctions",
new CircleFunctions()); }
}client side
package hello.client;public class Client {
public static void main(String[] args) {
try {
hello.client.jaxws.CircleFunctionsService service =
new hello.client.jaxws.CircleFunctionsService();
hello.client.jaxws.CircleFunctions port = service.getCircleFunctionsPort(); double arg0 = 3.0; double result = port.getArea(arg0);
System.out.println("Result = "+result);
} catch (Exception ex) {
ex.printStackTrace();
} }
}xml build file:
<project name="webservice.example" default="compilesrc" basedir=".">
<property file="build.properties" />
<property name="sourcedir" value="${basedir}/src" />
<property name="testscrdir" value="${basedir}/dev/test" />
<property name="targetdir" value="${basedir}/target" />
<property name="buildclass" value="${targetdir}" /> <target name="clean">
<delete dir="${buildclass}" />
<delete dir="${targetdir}" />
</target> <target name="compilesrc" depends="clean" >
<echo level="info" message="compile source code classes" />
<mkdir dir="${buildclass}" />
<javac debug="true" srcdir="${sourcedir}" destdir="${buildclass}" classpathref="libraries" />
</target> <target name="copy-resources">
<copy todir="${targetdir}">
<fileset dir="${sourcedir}">
<exclude name="**/*.java" />
</fileset>
</copy>
</target> <path id="jaxws.classpath">
<fileset dir="${jaxws.home}/jaxws_lib">
<include name="**/*.jar" />
</fileset>
</path> <path id="libraries">
<pathelement path="${buildclass}" />
<path refid="jaxws.classpath"/>
</path> <!-- Define the Jax WS ant tasks -->
<taskdef name="Apt" classname="com.sun.tools.ws.ant.Apt">
<classpath refid="libraries"/>
</taskdef> <!-- Define the Jax WS ant tasks -->
<taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport">
<classpath refid="libraries"/>
</taskdef>
<taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen">
<classpath refid="libraries"/>
</taskdef> <target name="genwsartifacts">
<wsgen sei="hello.CircleFunctions"
destdir="target" resourcedestdir="config" sourcedestdir="src"
keep="true" verbose="true" genwsdl="true" fork="true">
<classpath refid="libraries" />
</wsgen>
<wsimport debug="true" verbose="true" keep="true"
destdir="target" sourcedestdir="src"
package="hello.client.jaxws"
wsdl="config/CircleFunctionsService.wsdl">
</wsimport>
</target>
<target name="postprocess" description="Post process the wsdl and the schema files" depends="genwsartifacts">
<!-- Replace the URL token -->
<replace file="config/CircleFunctionsService.wsdl" token="REPLACE_WITH_ACTUAL_URL" value="${soap.address}"/>
<replace file="config/CircleFunctionsService_schema1.xsd" token="minOccurs="0""/>
</target>
</project>
本质上来说,任何在J2EE中应用的组件,都可以被移植到J2SE上