请问JSE1.6怎么实现webservice服务端

kivcare 2010-04-07 03:19:54
最近做完一个项目用的是JSE1.6,需要提供接口供主控计算机控制访问(用的是webservice),请问我如何在java工程里编程,才能让客户端访问我这里的应用程序,请说明的详细一些,本人对J2SE和web开发都不太懂,谢谢
...全文
196 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dwys0343 2010-04-08
  • 打赏
  • 举报
回复
gloomyfish 2010-04-08
  • 打赏
  • 举报
回复
另外你可以使用spring的standalone 的 web service component
本质上来说,任何在J2EE中应用的组件,都可以被移植到J2SE上
gloomyfish 2010-04-08
  • 打赏
  • 举报
回复
package hello;


import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService

public 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>

@井九 2010-04-07
  • 打赏
  • 举报
回复
用xfire 或者 axis
qqbz 2010-04-07
  • 打赏
  • 举报
回复
需要按照webservice方式写java程序。并需要发布到你们的系统(应该是个web应用)中。
这样你只要告诉客户的方法以及参数,你的客户就可以在他们自己的程序中使用你提供的功能。

至于如何用webservice方式写java程序并发布,需要参考一些资料。
liboofsc 2010-04-07
  • 打赏
  • 举报
回复
webservice应该是属于j2ee的内容吧,需要web容易的支持。
soli11722984 2010-04-07
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20080425/00/33A47C75-07D4-49E0-9628-BE23554AB142.html

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧