文章中的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中.
(二) 构造web服务
在这个conf文件夹中除了有binaryservice.wsdl外,还有两个文件:
config-client.xml,用来根据wsdl文件生成客户端访问服务所需要的制品.
<?xml version=”1.0″ encoding=”utf-8″?>
<configuration xmlns=”http://java.sun.com/xml/ns/jax-rpc/ri/config”>
<wsdl
location=”http://localhost:8080/netservice/binary?wsdl”
packagename=”wsidotnet” />
</configuration>
config-server.xml则用来根据binaryservice.wsdl生成服务器端制品,包括重新生成的sei接口文件,我们将利用这个文件编写服务实现,而不是前面提到的com.bin.iimage sei接口文件及其实现文件com.bin.imageimpl:
<?xml version=”1.0″ encoding=”utf-8″?>
<configuration xmlns=”http://java.sun.com/xml/ns/jax-rpc/ri/config”>
<wsdl location=”web-inf/conf/binaryservice.wsdl”
packagename=”wsidotnet” />
</configuration>
到目前为止,还有两个文件没有提供:
jaxrpc-ri.xml:
<?xml version=”1.0″ encoding=”utf-8″?>
<webservices xmlns=”http://java.sun.com/xml/ns/jax-rpc/ri/dd”
version=”1.0″
targetnamespacebase=”http://java.sun.com/xml/ns/jax-rpc/wsi/wsdl”
typenamespacebase=”http://java.sun.com/xml/ns/jax-rpc/wsi/types”
urlpatternbase=”/ws”>
<endpoint name=”imagebinaryservice” displayname=”stock example”
description=”stock example web service endpoint”
interface=”wsidotnet.iimage” implementation=”wsidotnet.iimage_impl”
model=”/web-inf/model.xml.gz” />
<endpointmapping endpointname=”imagebinaryservice” urlpattern=”/binary” />
</webservices>
web.xml文件:
<?xml version=”1.0″ encoding=”utf-8″?>
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee”
xmlns:xsi=”http://www.w3.org/2001/xmlschema-instance”
xsi:schemalocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”
version=”2.4″>
<context-param>
<param-name>binarypath</param-name>
<param-value>更改成你的本地文件路径</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.jws</welcome-file>
</welcome-file-list>
</web-app>
下面就是构建过程,首先,执行wsi server service得到服务器端的java制品,包括重新生成的sei,wscompile还生成了一个实现文件iimage_impl ,后面要修改这个类,在其中加入有用的方法.
wsidotnet.iimage清单:
package wsidotnet;
public interface iimage extends java.rmi.remote {
public wsidotnet.construcmsgresponse construcmsg(wsidotnet.construcmsg parameters) throws
java.rmi.remoteexception;
public wsidotnet.fetchfilelistresponse fetchfilelist(wsidotnet.fetchfilelist parameters) throws
java.rmi.remoteexception;
public wsidotnet.fetchimageresponse fetchimage(wsidotnet.fetchimage parameters) throws
java.rmi.remoteexception;
public wsidotnet.getfilelistresponse getfilelist(wsidotnet.getfilelist parameters) throws
java.rmi.remoteexception;
}
和前面的com.bin.iimage接口相比很不同了.因为采用文档样式的绑定,所以这里就产生了所谓的包装类了.
实现文件为:
package wsidotnet;
import java.io.file;
import java.io.fileinputstream;
import java.nio.mappedbytebuffer;
import java.nio.channels.filechannel;
import java.util.calendar;
import java.util.date;
import javax.servlet.servletcontext;
import javax.xml.rpc.serviceexception;
import javax.xml.rpc.server.servicelifecycle;
import javax.xml.rpc.server.servletendpointcontext;
public class iimage_impl implements wsidotnet.iimage, java.rmi.remote,servicelifecycle {
servletendpointcontext servletendpointcontext = null;
string binarypath = “”;
servletcontext servletcontext = null;
public wsidotnet.construcmsgresponse construcmsg(wsidotnet.construcmsg parameters) throws
java.rmi.remoteexception {
wsidotnet.construcmsgresponse _retval = null;
return _retval;
}
public wsidotnet.fetchfilelistresponse fetchfilelist(wsidotnet.fetchfilelist parameters) throws
java.rmi.remoteexception {
wsidotnet.fetchfilelistresponse _retval = new fetchfilelistresponse();
_retval.setresult(fetchfilelist());
return _retval;
}
public wsidotnet.fetchimageresponse fetchimage(wsidotnet.fetchimage parameters) throws
java.rmi.remoteexception {
wsidotnet.fetchimageresponse _retval = new fetchimageresponse();
_retval.setresult(fetchimage(parameters.getstring_1()));
return _retval;
}
public wsidotnet.getfilelistresponse getfilelist(wsidotnet.getfilelist parameters) throws
java.rmi.remoteexception {
wsidotnet.getfilelistresponse _retval = null;
return _retval;
}
private fileinfo[] fetchfilelist() {
file file = new file(this.binarypath);
system.out.println(this.binarypath);
file[] c = file.listfiles();
fileinfo[] fis = new fileinfo[c.length];
for (int i = 0; i < c.length; i++) {
fileinfo fi = new fileinfo();
fi.setisdir(c[i].isdirectory());
fi.setfilename(c[i].getname());
fi.setfilelength(c[i].length());
fi.setfilepath(c[i].getabsolutepath());
calendar cal=calendar.getinstance();
cal.settime(new date(c[i].lastmodified()));
fi.setcreatedate(cal);
fis[i] = fi;
}
return fis;
}
private byte[] fetchimage(string sn) {
file file = new file(sn);
byte[] b=null;
mappedbytebuffer buffer = null;
try {
fileinputstream is = new fileinputstream(file);
b=new byte[(int)file.length()];
is.read(b,0,(int)file.length());
/*
filechannel fc = is.getchannel();
buffer = fc.map(filechannel.mapmode.read_only, 0, file.length());
buffer.get
*/
} catch (exception ex) {
system.out.println(ex);
}
//return buffer.array();
return b;
}
public void destroy() {
// todo auto-generated method stub
servletendpointcontext = null;
servletcontext = null;
}
public void init(object arg0) throws serviceexception {
// todo auto-generated method stub
servletendpointcontext = (servletendpointcontext) arg0;
servletcontext = servletendpointcontext.getservletcontext();
binarypath = servletcontext.getinitparameter(“binarypath”);
}
}
这里展示的实现类,已经过修改,让它扩展了servicelifecycle接口,以便运行环境送给它小金豆.这里就是获得了文件路径.此外,还提供了两个私有方法:fetchimage,fetchfilelist用于具体执行功能,这里也可以把这两个方法移动到一个新类,然后iimage_impl使用这个新类,使iimage_impl类变成调用者对外部类的适配器,这样就形成了一个适配器模式.
完成以上修改后,继续执行ant 任务:create-war,deploy后,得到了可供发布的netservice.war进行发布.本例使用tomcat5,检查http://localhost:8080/netservice/binary?wsdl是否装入.
发布成功后,用vs新建一个c#项目,通过这个地址http://localhost:8080/netservice/binary?wsdl引用这个服务,然后编写以下类:
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using testws.binary;
namespace testws
{
/// <summary>
/// form1 的摘要说明。
/// </summary>
public class form1 : system.windows.forms.form
{
private system.windows.forms.button button1;
private system.windows.forms.listbox listbox1;
private system.windows.forms.picturebox picturebox1;
private system.windows.forms.statusbar statusbar1;
private system.windows.forms.statusbarpanel statusbarpanel1;
private system.windows.forms.statusbarpanel statusbarpanel2;
testws.binary.iimagebinding imagelist;
private system.windows.forms.panel panel1;
private system.windows.forms.panel panel2;
private system.windows.forms.panel panel3;
private system.windows.forms.panel panel4;
private system.windows.forms.splitter splitter1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private system.componentmodel.container components = null;
public form1()
{
//
// windows 窗体设计器支持所必需的
//
initializecomponent();
//
// todo: 在 initializecomponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}
#region windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 – 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void initializecomponent()
{
this.button1 = new system.windows.forms.button();
this.listbox1 = new system.windows.forms.listbox();
this.picturebox1 = new system.windows.forms.picturebox();
this.statusbar1 = new system.windows.forms.statusbar();
this.statusbarpanel1 = new system.windows.forms.statusbarpanel();
this.statusbarpanel2 = new system.windows.forms.statusbarpanel();
this.panel1 = new system.windows.forms.panel();
this.panel2 = new system.windows.forms.panel();
this.panel3 = new system.windows.forms.panel();
this.panel4 = new system.windows.forms.panel();
this.splitter1 = new system.windows.forms.splitter();
((system.componentmodel.isupportinitialize)(this.statusbarpanel1)).begininit();
((system.componentmodel.isupportinitialize)(this.statusbarpanel2)).begininit();
this.panel1.suspendlayout();
this.panel2.suspendlayout();
this.panel3.suspendlayout();
this.panel4.suspendlayout();
this.suspendlayout();
//
// button1
//
this.button1.location = new system.drawing.point(24, 8);
this.button1.name = “button1”;
this.button1.size = new system.drawing.size(56, 23);
this.button1.tabindex = 0;
this.button1.text = “装入”;
this.button1.click += new system.eventhandler(this.button1_click);
//
// listbox1
//
this.listbox1.borderstyle = system.windows.forms.borderstyle.fixedsingle;
this.listbox1.dock = system.windows.forms.dockstyle.fill;
this.listbox1.itemheight = 12;
this.listbox1.location = new system.drawing.point(0, 0);
this.listbox1.name = “listbox1”;
this.listbox1.size = new system.drawing.size(136, 230);
this.listbox1.tabindex = 1;
this.listbox1.selectedindexchanged += new system.eventhandler(this.listbox1_selectedindexchanged);
//
// picturebox1
//
this.picturebox1.borderstyle = system.windows.forms.borderstyle.fixedsingle;
this.picturebox1.dock = system.windows.forms.dockstyle.fill;
this.picturebox1.location = new system.drawing.point(0, 0);
this.picturebox1.name = “picturebox1”;
this.picturebox1.size = new system.drawing.size(261, 231);
this.picturebox1.tabindex = 2;
this.picturebox1.tabstop = false;
//
// statusbar1
//
this.statusbar1.location = new system.drawing.point(0, 271);
this.statusbar1.name = “statusbar1”;
this.statusbar1.panels.addrange(new system.windows.forms.statusbarpanel[] {
this.statusbarpanel1,
this.statusbarpanel2});
this.statusbar1.showpanels = true;
this.statusbar1.size = new system.drawing.size(400, 22);
this.statusbar1.tabindex = 3;
this.statusbar1.text = “statusbar1”;
//
// statusbarpanel1
//
this.statusbarpanel1.autosize = system.windows.forms.statusbarpanelautosize.contents;
this.statusbarpanel1.width = 10;
//
// statusbarpanel2
//
this.statusbarpanel2.autosize = system.windows.forms.statusbarpanelautosize.spring;
this.statusbarpanel2.width = 374;
//
// panel1
//
this.panel1.controls.add(this.listbox1);
this.panel1.dock = system.windows.forms.dockstyle.left;
this.panel1.location = new system.drawing.point(0, 0);
this.panel1.name = “panel1”;
this.panel1.size = new system.drawing.size(136, 231);
this.panel1.tabindex = 4;
//
// panel2
//
this.panel2.controls.add(this.button1);
this.panel2.dock = system.windows.forms.dockstyle.top;
this.panel2.location = new system.drawing.point(0, 0);
this.panel2.name = “panel2”;
this.panel2.size = new system.drawing.size(400, 40);
this.panel2.tabindex = 5;
//
// panel3
//
this.panel3.controls.add(this.panel4);
this.panel3.controls.add(this.splitter1);
this.panel3.controls.add(this.panel1);
this.panel3.dock = system.windows.forms.dockstyle.fill;
this.panel3.location = new system.drawing.point(0, 40);
this.panel3.name = “panel3”;
this.panel3.size = new system.drawing.size(400, 231);
this.panel3.tabindex = 6;
//
// panel4
//
this.panel4.controls.add(this.picturebox1);
this.panel4.dock = system.windows.forms.dockstyle.fill;
this.panel4.location = new system.drawing.point(139, 0);
this.panel4.name = “panel4”;
this.panel4.size = new system.drawing.size(261, 231);
this.panel4.tabindex = 5;
//
// splitter1
//
this.splitter1.location = new system.drawing.point(136, 0);
this.splitter1.name = “splitter1”;
this.splitter1.size = new system.drawing.size(3, 231);
this.splitter1.tabindex = 6;
this.splitter1.tabstop = false;
//
// form1
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(400, 293);
this.controls.add(this.panel3);
this.controls.add(this.statusbar1);
this.controls.add(this.panel2);
this.name = “form1”;
this.text = “ws-i demo—access sun ws”;
this.load += new system.eventhandler(this.form1_load);
((system.componentmodel.isupportinitialize)(this.statusbarpanel1)).endinit();
((system.componentmodel.isupportinitialize)(this.statusbarpanel2)).endinit();
this.panel1.resumelayout(false);
this.panel2.resumelayout(false);
this.panel3.resumelayout(false);
this.panel4.resumelayout(false);
this.resumelayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[stathread]
static void main()
{
application.run(new form1());
}
private void form1_load(object sender, system.eventargs e)
{
listbox1.items.clear();
panel4.autoscroll =true;
picturebox1.sizemode= pictureboxsizemode.autosize;
imagelist=new testws.binary.iimagebinding();
}
private void button1_click(object sender, system.eventargs e)
{
testws.binary.fetchfilelist fl=new fetchfilelist();
listbox1.items.clear();
//testws.binary.
fileinfo[] fis= imagelist.fetchfilelist(fl);
if(fis!=null)
console.writeline(fis.length);
foreach(fileinfo info in fis)
{
//console.writeline(info.filepath+” “+ info.createdate);
listbox1.items.add(info.filepath);
}
//testws.binary.helloifbinding bind=new helloifbinding();
}
private void listbox1_selectedindexchanged(object sender, system.eventargs e)
{
listbox lb=(listbox)sender;
if(lb.selecteditem!=null)
{
statusbar1.panels[0].text=lb.selecteditem.tostring();
testws.binary.fetchimage fn=new fetchimage();
fn.string_1=lb.selecteditem.tostring();
testws.binary.fetchimageresponse res=imagelist.fetchimage(fn);
try
{
system.io.memorystream ms=new system.io.memorystream(res.result);
image image=image.fromstream(ms);
picturebox1.image=image;
panel4.autoscrollminsize=picturebox1.size;
}
catch(exception ex)
{
console.writeline(ex.stacktrace);
}
}
}
}
}
测试界面:
到此,在c#访问java ws的过程结束了,实现互操作性关键在于要生成遵守ws-i的javaweb服务制品,这样的服务才可以跨不同平台操作.