扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
文章中的WS服务使得这个服务可以在DotNet环境中调用。
文件清单:
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}" includes="WEB-INF/**, build/**" />
</war>
<copy file="${assemble.war}/${raw.war.file}" todir="." />
</target>
<target name="genstaticstub" description="生成静态桩,供静态的调用服务">
<echo message="gen statics tub" />
<wscompile client="true" features="wsi,documentliteral" keep="true" base="." sourceBase="." xPrintStackTrace="true" config="config-wsdl.xml" verbose="true">
<classpath refid="compile.classpath" />
</wscompile>
</target>
<target name="generate-dynamic-interface" description="根据WSDL文件生成SEI及其它材料,供动态调用 norpcstructures">
<echo message="generate dynamic interface" />
<wscompile import="true" keep="false" features="wsi,documentliteral" base="./dynmicstub" sourceBase="./dynmicstub" xPrintStackTrace="true" config="config-wsdl.xml" verbose="true">
<classpath refid="compile.classpath" />
</wscompile>
</target>
<target depends="prepare" name="wsi server service" description="Generating WS-I Compliant Service Files with wscompile 根据WSDL文件生成SEI及其它材料,供动态调用 norpcstructures">
<echo message="generate-server ,generate wsi server service" />
<wscompile import="true" define="false" keep="false" features="wsi,documentliteral" base="${wsi.server.dir}" sourceBase="${wsi.server.dir}" xPrintStackTrace="true" model="model.xml.gz" config=".\conf\config-server.xml" verbose="true">
<classpath refid="compile.classpath" />
</wscompile>
</target>
<target depends="prepare" name="wsi client service" description="Generating WS-I Compliant Service Files with wscompile 根据WSDL文件生成SEI及其它材料,供动态调用 norpcstructures">
<echo message="generate wsi client service" />
<wscompile client="true" keep="true" features="wsi,documentliteral" base="${wsi.client.dir}" sourceBase="${wsi.client.dir}" xPrintStackTrace="true" config=".\conf\config-client.xml" verbose="true">
<classpath refid="compile.classpath" />
</wscompile>
</target>
</project>
在这个构建文件中的build任务中, features的值指定为"wsi,documentliteral",这个任务需要的config-interface.xml:
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<service name="BinaryService" targetNamespace="urn:binary"
typeNamespace="urn:binary" packageName="com.binary">
<interface name="com.bin.IImage"
servantName="com.bin.ImageImpl" />
</service>
</configuration>
这个文件的需要的com.bin.IImage SEI接口文件及其实现文件com.bin.ImageImpl:
public interface IImage extends Remote {
//public DataHandler fetchImg(String sn) throws RemoteException;
//public DataHandler[] fetchImgs(String[] sn) throws RemoteException;
public SOAPMessage construcMsg(String[] fn) throws RemoteException;
public byte[] fetchImage(String sn) throws RemoteException;
public FileInfo[] fetchFileList() throws java.rmi.RemoteException;
public FileInfo getFileList(String fn) throws java.rmi.RemoteException;
}
DataHandler,ArrayList属于java的类当然不允许出现在接口中了,因为C#不认识这些类,FileInfo值类型类倒支持,因为这个类没有方法,而且数据类型都是可以用SOAP来表示的,C#是可以理解的.
实现文件,注意实现的方法是空方法.
public class ImageImpl implements IImage {
public SOAPMessage construcMsg(String[] fn) throws RemoteException {
return null;
}
public byte[] fetchImage(String sn) throws RemoteException{
return null;
}
public FileInfo[] fetchFileList() throws java.rmi.RemoteException{
return null;
}
public FileInfo getFileList(String fn) throws RemoteException {
return null;
}
}
到这里,为互操作所做的修改只是在 features的值指定为"wsi,documentliteral",其它地方没有修改包括config-interface.xml接口配置文件.通过执行这个任务,可以得到我们想要的BinaryService.wsdl文件.位于nonclass文件夹中,把它移动到conf中.
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者