网站:
JavaEye 作者:
jacally 链接:
http://lib.javaeye.com/blog/170628 发表时间: 2008年03月12日
声明:本文系JavaEye网站发布的原创博客文章,未经作者书面许可,严禁任何网站转载本文,否则必将追究法律责任!
1.首先在vs中新建项目
2.添加web引用....
3.输入WebService地址:http://88.148.29.54:8080/aio/services/WebServiceSample?wsdl最后点击“添加引用”
4.创建一个简单的form
5.编写按钮事件代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Net;
using System.Windows.Forms;
using WindowsApplication1.WebReference;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
WindowsApplication1.WebReference.WebServiceSampleImplService service = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String str = "";
try
{
str = service.say("Libin");
}
catch (Exception we)
{
str = we.Message;
}
//MessageBox.Show(str);
textBox1.Text = str ;
}
private void Form1_Load(object sender, EventArgs e)
{
service = new WebServiceSampleImplService();
label1.Text = "WS.url:" + service.Url + "\r\n";
}
private void button2_Click(object sender, EventArgs e)
{
String str = "";
try
{
User user = new User();
user.id = 1;
user.name = "Libin";
str = "userName:" + service.sayUserName(user);
}
catch (Exception we)
{
str = we.Message;
}
//MessageBox.Show(str);
textBox1.Text = str;
}
private void button3_Click(object sender, EventArgs e)
{
String str = "";
try
{
Object[] users = service.findUsers();
for (int i = 0; i < users.Length; i++)
{
User user = (User)users[i];
str += "id:"+user.id + " name:" + user.name + "\r\n";
}
}
catch (Exception we)
{
str = we.Message;
}
//MessageBox.Show(str);
textBox1.Text = str;
}
}
}
6.最后点击调试运行,或按F5运行,通过点击按钮就可以看到调用WebService的运行结果了
本文的讨论也很精彩,浏览讨论>>
JavaEye推荐
中国领先的电子商务网站-淘宝网招贤纳士,诚聘Java工程师
文章来源:
http://lib.javaeye.com/blog/170628
posted on 2008-03-16 21:41
Lib 阅读(691)
评论(0) 编辑 收藏 所属分类:
Java