在上一篇文章中,我们创建了一个web服务,下面,我们通过创建一个客户端,来使用这个web服务。

我们新建一个c# winform项目,界面如下:

使用web服务查询数据库的例子(下)

在项目中,添加web引用,就是刚才的那个web服务的地址: http://localhost:2074/Service1.asmx(你在调试那个服务时就会给出了),现在你最好重新让那个服务

开启(打开那个项目并且运行。)

添加名字我们用默认的localhost,然后再button1按钮添加事件代码:

 

 sender, EventArgs e)
        {
            if (textBox1.Text.Length > 0)
            {
                localhost.Service1 sc 
= new WindowsService.localhost.Service1();
                textBox2.Text 
= sc.GetCustomerAddress(textBox1.Text);
            }
        }

 

运行一下看看吧。

相关文章:

  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2021-06-10
  • 2022-12-23
  • 2022-02-15
  • 2022-01-04
猜你喜欢
  • 2021-12-27
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2021-11-17
  • 2021-09-17
  • 2022-12-23
相关资源
相似解决方案