扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
文章中的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,检查ttp://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服务制品,这样的服务才可以跨不同平台操作.
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者