分享
 
 
 

Java WS和C#调用

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

互操作性是Web Service的真正优势,虽然关于WS标准有很多,但不同厂家都是自己的实现,不同实现之间的互操作性因此很差,于是有了WS-I组织成立来管理这种差异,并提供统一的互操作性规范,到目前为止,这些工作仍在进行中,不过成果早已经有了:WS-I Attachment Profile 1.0 并且也已经在Sun提供的WS设施上有了体现,通过使用wscompile 工具中的选项 -f wsi 即可生成兼容WS-I规范的java制品.本文通过修改前一篇http://blog.csdn.net/keepeye/services/trackbacks/408145.aspx

文章中的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[url=http://localhost:8080/netservice/binary?WSDL][/url]引用这个服务,然后编写以下类:

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服务制品,这样的服务才可以跨不同平台操作.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有