7.7  WinForm如何调用Web Service

本节介绍WinForm如何调用Web Service。

7.7.1  .NET的WinForm调用Web Service

在.NET的WinForm中调用Web Service的操作基本上和在ASP.NET中调用Web Service是一样。(完整代码示例位置:光盘\code\ch07\WinFormsAppClient)

首先在项目上单击鼠标右键,在弹出的快捷菜单中选择"添加Web引用"命令,如图7-11所示。

添加完引用后,项目中也会创建一个名叫Web References的目录,即引用代理类,如图7-12所示。

7.7.1 .NET的WinForm调用Web Service 
图7-11  添加Web引用
7.7.1 .NET的WinForm调用Web Service 
图7-12  Web引用代理类

代码中使用这个代理类进行调用。

  1. ProductService.LTPService service = new ProductService.LTPService();  
  2. string price=service.GetProductPrice("001");  
  3. MessageBox.Show(price); 

微软的统一编程模型,真是让我们感觉开发变得简单多了。

相关文章:

  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-08-23
  • 2022-12-23
  • 2021-11-04
  • 2021-06-09
猜你喜欢
  • 2021-07-08
  • 2021-10-05
  • 2021-09-14
  • 2022-02-25
相关资源
相似解决方案