互操作性是Web Service的真正优势虽然关于WS标准有很多但不同厂家都是自己的实现不同实现之间的互操作性因此很差于是有了WSI组织成立来管理这种差异并提供统一的互操作性规范到目前为止这些工作仍在进行中不过成果早已经有了:WSI Attachment Profile 并且也已经在Sun提供的WS设施上有了体现通过使用wscompile 工具中的选项 f wsi 即可生成兼容WSI规范的java制品
文件清单:
SEI接口类IImagejava实现SEI接口的类IIMageImpljava描述文件信息的值类型类FileInfojavaWeb应用部署描述文件webxmlWS发布配置文件jaxrpcrixmlWS编译配置文件configinterfacexml构建客户端桩的configwsdlxml构建文件builderxml
客户端测试类:Formcs
本例是从WSDL开始的因此我们要有一个WSDL文件第一步就是得到这个文件
(一) 得到WSDL文件
为达到互操作要求这个文件的描述必须是文档样式的绑定文字格式的编码为得到此文件首先介绍构建文件builderxml:
<?xml version= encoding=GBK?>
<project name=webservice default=build basedir=>
<property name=jaxrpclibdir value=I:\jwsdp\jaxrpc\lib>
</property>
<property name=jaxrpclibdir value=D:\Sun\AppServer\lib>
</property>
<property name=classesdir value=\build\classes>
</property>
<property name=srcdir value=\build\src>
</property>
<property name=rawwarfile value=netservicerawwar>
</property>
<property name=cookwarfile value=netservicewar>
</property>
<property name=nonclassdir value=\build\nonclass>
</property>
<property name=build value=${nonclassdir}>
</property>
<property name=assemble value=\assemble>
</property>
<property name=assemblewar value=\assemble\war>
</property>
<property name=assembleear value=\assemble\ear>
</property>
<property name=wsidir value=\wsi>
</property>
<property name=wsiserverdir value=\wsi\server>
</property>
<property name=wsiclientdir value=\wsi\client>
</property>
<property name=tmpdir value=\tmp>
</property>
<path id=jaxrpcclasspath>
<fileset dir=${jaxrpclibdir}>
<include name=**/*jar />
</fileset>
<fileset dir=D:\jdbc\postgresql>
<include name=*jar />
</fileset>
</path>
<path id=compileclasspath>
<fileset dir=${jaxrpclibdir}>
<include name=**/*jar />
</fileset>
<fileset dir=D:\jwsdp\jaxrpc\lib>
<include name=**/*jar />
</fileset>
</path>
<path id=jaxrpcclasspath>
<fileset dir=${jaxrpclibdir}>
<include name=**/*jar />
</fileset>
<fileset dir=I:\jwsdp\jwsdpshared\lib>
<include name=**/*jar />
</fileset>
<fileset dir=I:\jwsdp\jaxp\lib>
<include name=**/*jar />
</fileset>
<fileset dir=I:\jwsdp\jaxp\lib\endorsed>
<include name=**/*jar />
</fileset>
<fileset dir=D:\jdbc\postgresql>
<include name=*jar />
</fileset>
</path>
<path id=compileclasspath>
<fileset dir=${jaxrpclibdir}>
<include name=**/*jar />
</fileset>
<fileset dir=I:\jwsdp\jaxp\lib>
<include name=**/*jar />
</fileset>
<fileset dir=I:\jwsdp\jaxp\lib\endorsed>
<include name=**/*jar />
</fileset>
<fileset dir=I:\jwsdp\jwsdpshared\lib>
<include name=**/*jar />
</fileset>
<fileset dir=I:\jwsdp\saaj\lib>
<include name=**/*jar />
</fileset>
<fileset dir=H:\jakartatomcat\common\lib>
<include name=servletapijar />
</fileset>
</path>
<taskdef name=wscompile classpat classname=comsunxmlrpctoolsantWscompile>
</taskdef>
<taskdef name=wsdeploy classpat classname=comsunxmlrpctoolsantWsdeploy>
</taskdef>
<target name=prepare>
<mkdir dir=${srcdir} />
<mkdir dir=${nonclassdir} />
<mkdir dir=${classesdir} />
<mkdir dir=${assemble} />
<mkdir dir=${assemblewar} />
<mkdir dir=${assembleear} />
<mkdir dir=${wsidir} />
<mkdir dir=${wsiserverdir} />
<mkdir dir=${wsiclientdir} />
<mkdir dir=${tmpdir} />
</target>
<target name=compileclass depends=prepare>
<echo message=Compiling the java source code />
<property name=src value=${src}>
</property>
<property name=dest value=${build}>
</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=compileclasspath />
</javac>
</target>
<target name=build depends=prepare description=生成java制品如生成可供wsdeploy使用的web档案称为生war就象作菜一样先顺菜以及modelwsdl文件这里生成的WSDL文件wsdeploy并不使用>
<echo message=build the WAR />
<wscompile import=false features=wsidocumentliteral define=true gen=false keep=true base=${classesdir} sourceBase=${srcdir} classpath=\classes nonClassDir=${nonclassdir} model=modelxmlgz xPrintStackTrace=true config=configinterfacexml verbose=true>
<classpath refid=compileclasspath />
</wscompile>
</target>
<target name=deploy depends=prepare description=生成可供发布的web档案称为煮熟的war这个阶段也生成了WSDL文件并被直接打包了>
<echo message=deploy the WAR />
<wsdeploy keep=false verbose=true tmpDir=${tmpdir} outWarFile=${cookwarfile} inWarFile=${rawwarfile}>
<classpath refid=compileclasspath />
</wsdeploy>
</target>
<target name=createwar description=打包由wscompile生成的制品以及所有发布所用的材料>
<echo message=buildwar Creating the WAR />
<antcall target=compileclass>
<param name=src value=${wsiserverdir} />
<param name=build value=${wsiserverdir} />
</antcall>
<delete file=${assemblewar}/${warfile} />
<delete dir=${assemblewar}/WEBINF />
<copy todir=${assemblewar}/WEBINF/classes/>
<fileset dir=${wsiserverdir} includes=**/*class excludes=**/*Clientclass **/*wsdl **/*mappingxml />
</copy>
<copy todir=${assemblewar}/WEBINF/lib/>
<fileset dir=/lib includes=**/*jar excludes=**/*Clientclass **/*wsdl **/*mappingxml />
</copy>
<copy file=\conf\BinaryServicewsdl todir=${assemblewar}/WEBINF />
<copy file=jaxrpcrixml todir=${assemblewar}/WEBINF />
<copy file=modelxmlgz todir=${assemblewar}/WEBINF />
<war destfile=${assemblewar}/${rawwarfile} webxml=/webxml filesonly=true>
<fileset dir=${assemblewar} includ