62,621
社区成员
发帖
与我相关
我的任务
分享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());
}
}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();
}
}
}<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>