互操作性是Web Service的真正优势,虽然关于WS标准有很多,但不同厂家都是自己的实现,不同实现之间的互操作性因此很差,于是有了WS-I组织成立来治理这种差异,并提供统一的互操作性规范,到目前为止,这些工作仍在进行中,不过成果早已经有了:WS-I Attachment Profile 1.0 并且也已经在Sun提供的WS设施上有了体现,通过使用wscompile 工具中的选项 -f wsi 即可生成兼容WS-I规范的Java制品.
文件清单:
SEI接口类IImage.java,实现SEI接口的类IIMageImpl.java,描述文件信息的值类型类FileInfo.java,Web应用部署描述文件web.XML,WS发布配置文件jaxrpc-ri.xml,WS编译配置文件config-interface.xml,构建客户端桩的config-wsdl.xml,构建文件builder.xml
客户端测试类:Form1.cs.
本例是从WSDL开始的,因此我们要有一个WSDL文件.第一步就是得到这个文件.
(一) 得到WSDL文件.
为达到互操作要求,这个文件的描述必须是文档样式的绑定,文字格式的编码.为得到此文件,首先介绍构建文件builder.xml:
<?xml version="1.0" encoding="GBK"?
<project name="webservice" default="build" basedir="."
<property name="jaxrpc.lib.dir" value="I:\jwsdp-1.6\jaxrpc\lib"
</property
<property name="jaxrpc.lib.dir1" value="D:\Sun\AppServer\lib"
</property
<property name="classes.dir" value=".\build\classes"
</property
<property name="src.dir" value=".\build\src"
</property
<property name="raw.war.file" value="netservice-raw.war"
</property
<property name="cook.war.file" value="netservice.war"
</property
<property name="nonclass.dir" value=".\build\nonclass"
</property
<property name="build" value="${nonclass.dir}"
</property
<property name="assemble" value=".\assemble"
</property
<property name="assemble.war" value=".\assemble\war"
</property
<property name="assemble.ear" value=".\assemble\ear"
</property
<property name="wsi.dir" value=".\wsi"
</property
<property name="wsi.server.dir" value=".\wsi\server"
</property
<property name="wsi.client.dir" value=".\wsi\client"
</property
<property name="tmp.dir" value=".\tmp"
</property
<path id="jaxrpc-classpath1"
<fileset dir="${jaxrpc.lib.dir}"
<include name="**/*.jar" /
</fileset
<fileset dir="D:\jdbc\postgresql"
<include name="*.jar" /
</fileset
</path
<path id="compile.classpath1"
<fileset dir="${jaxrpc.lib.dir}"
<include name="**/*.jar" /
</fileset
<fileset dir="D:\jwsdp-1.5\jaxrpc\lib"
<include name="**/*.jar" /
</fileset
</path
<path id="jaxrpc-classpath"
<fileset dir="${jaxrpc.lib.dir}"
<include name="**/*.jar" /
</fileset
<fileset dir="I:\jwsdp-1.6\jwsdp-shared\lib"
<include name="**/*.jar" /
</fileset
<fileset dir="I:\jwsdp-1.6\jaXP\lib"
<include name="**/*.jar" /
</fileset
<fileset dir="I:\jwsdp-1.6\jaxp\lib\endorsed"
<include name="**/*.jar" /
</fileset
<fileset dir="D:\jdbc\postgresql"
<include name="*.jar" /
</fileset
</path
<path id="compile.classpath"
<fileset dir="${jaxrpc.lib.dir}"
<include name="**/*.jar" /
</fileset
<fileset dir="I:\jwsdp-1.6\jaxp\lib"
<include name="**/*.jar" /
</fileset
<fileset dir="I:\jwsdp-1.6\jaxp\lib\endorsed"
<include name="**/*.jar" /
</fileset
<fileset dir="I:\jwsdp-1.6\jwsdp-shared\lib"
<include name="**/*.jar" /
</fileset
<fileset dir="I:\jwsdp-1.6\saaj\lib"
<include name="**/*.jar" /
</fileset
<fileset dir="H:\jakarta-tomcat-5.5.9\common\lib"
<include name="servlet-api.jar" /
</fileset
</path
<taskdef name="wscompile" classpathref="jaxrpc-classpath" classname="com.sun.xml.rpc.tools.ant.Wscompile"
</taskdef
<taskdef name="wsdeploy" classpathref="jaxrpc-classpath" classname="com.sun.xml.rpc.tools.ant.Wsdeploy"
</taskdef
<target name="prepare"
<mkdir dir="${src.dir}" /
<mkdir dir="${nonclass.dir}" /
<mkdir dir="${classes.dir}" /
<mkdir dir="${assemble}" /
<mkdir dir="${assemble.war}" /
<mkdir dir="${assemble.ear}" /
<mkdir dir="${wsi.dir}" /
<mkdir dir="${wsi.server.dir}" /
<mkdir dir="${wsi.client.dir}" /
<mkdir dir="${tmp.dir}" /
</target
<target name="compile-class" depends="prepare"
<echo message="Compiling the java source code...." /
<property name="src" value="${src1}"
</property
<property name="dest" value="${build1}"
</property
<echo message="src=${src}build=${dest}" /
<echo message="delete class in dir ${src} ...." /
<delete
<fileset dir="${src}"
<include name="**/*.class" /
<exclude name="exclude" /
</fileset
</delete
<echo message="recompile java in dir ${src} ...." /
<javac srcdir="${src}" destdir="${dest}" includes="**/*.java" excludes="hhhhhh"
<classpath refid="compile.classpath" /
</javac
</target
<target name="build" depends="prepare" description="生成java制品,如生成可供wsdeploy使用的web档案,称为生war,就象作菜一样,先顺菜,以及model,wsdl文件,这里生成的WSDL文件,wsdeploy并不使用"
<echo message="build the WAR...." /
<wscompile import="false" features="wsi,documentliteral" define="true" gen="false" keep="true" base="${classes.dir}" sourceBase="${src.dir}" classpath=".\classes" nonClassDir="${nonclass.dir}" model="model.xml.gz" xPrintStackTrace="true" config="config-interface.xml" verbose="true"
<classpath refid="compile.classpath" /
</wscompile
</target
<target name="deploy" depends="prepare" description="生成可供发布的web档案,称为煮熟的war,这个阶段也生成了WSDL文件并被直接打包了"
<echo message="deploy the WAR...." /
<wsdeploy keep="false" verbose="true" tmpDir="${tmp.dir}" outWarFile="${cook.war.file}" inWarFile="${raw.war.file}"
<classpath refid="compile.classpath" /
</wsdeploy
</target
<target name="create-war" description="打包由wscompile生成的制品,以及所有发布所用的材料"
<echo message="build-war Creating the WAR...." /
<antcall target="compile-class"
<param name="src1" value="${wsi.server.dir}" /
<param name="build1" value="${wsi.server.dir}" /
</antcall
<delete file="${assemble.war}/${war.file}" /
<delete dir="${assemble.war}/WEB-INF" /
<copy todir="${assemble.war}/WEB-INF/classes/"
<fileset dir="${wsi.server.dir}" includes="**/*.class" excludes="**/*Client.class, **/*.wsdl, **/*mapping.xml" /
</copy
<copy todir="${assemble.war}/WEB-INF/lib/"
<fileset dir="./lib" includes="**/*.jar" excludes="**/*Client.class, **/*.wsdl, **/*mapping.xml" /
</copy
<copy file=".\conf\BinaryService.wsdl" todir="${assemble.war}/WEB-INF" /
<copy file="jaxrpc-ri.xml" todir="${assemble.war}/WEB-INF" /
<copy file="model.xml.gz" todir="${assemble.war}/WEB-INF" /
<war destfile="${assemble.war}/${raw.war.file}" webxml="./web.xml" filesonly="true"
<fileset dir="${assemble.war}" includ