扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
发布成功后,用VS新建一个C#项目,通过这个地址ttp://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)- 科技行者