微软对于VS2003 Web Service给予的正面解答

开发 后端
对于VS2003大家都很熟悉了,他的安全性也在不断提高。保障VS2003 Web Service的安全性是完全有必要的,但前提是要深入理解到底什么是VS2003 Web Service,及他是怎么运作的。

本文介绍关于VS2003 Web Service的一些常出现的问题和状况,怎样创建VS2003 Web Service。这些内容都是和各位老师还有论坛学习到的,中间可能有不少错误是我没有挑出的,欢迎大家指正。

“MS.NET平台内建了对VS2003 Web Service的支持,包括Web Service的构建和使用。与其它开发平台不同,使用.NET平台,你不需要其他的工具或者SDK就可以完成Web Service的开发了。.NET Framework本身就全面支持Web Service,包括服务器端的请求处理器和对客户端发送和接受SOAP消息的支持”(前面这句话是icech借用别人的)。本文将一步一步带你用Microsoft Visual Studio .NET 2003(后面简称VS.Net 2003)创建和使用一个简单的Web Service。

1、用VS.Net 2003创建一个最简单的Web Service

首先,打开VS.Net 2003, 按Ctrl+Shift+N(或者打开“文件-新建-项目”),选择“ASP.NET Web服务”。生成WebService默认文件是Service1.asmx

查看Service1.asmx.cs代码,你会发现VS.Net 2003已经为Web Service文件建立了缺省的框架。原始代码为:

  1. using System;  
  2. using System.Collections;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Diagnostics;  
  6. using System.Web;  
  7. using System.Web.Services;   
  8. namespace WebService1  
  9. {  
  10. ///   
  11. /// Service1 的摘要说明。  
  12. ///   
  13. public class Service1 : System.Web.Services.WebService  
  14. {  
  15. public Service1()  
  16. {  
  17. //CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的  
  18. InitializeComponent();  
  19. }  
  20.  
  21. #region 组件设计器生成的代码  
  22.  
  23. //Web 服务设计器所必需的  
  24. private IContainer components = null;  
  25.  
  26. ///   
  27. /// 设计器支持所需的方法 - 不要使用代码编辑器修改  
  28. /// 此方法的内容。  
  29. ///   
  30. private void InitializeComponent()  
  31. {  
  32. }  
  33.  
  34. ///   
  35. /// 清理所有正在使用的资源。  
  36. ///   
  37. protected override void Dispose( bool disposing )  
  38. {  
  39. if(disposing && components != null)  
  40. {  
  41. components.Dispose();  
  42. }  
  43. base.Dispose(disposing);   
  44. }  
  45.  
  46. #endregion  
  47.  
  48. // WEB 服务示例  
  49. // HelloWorld() 示例服务返回字符串 Hello World  
  50. // 若要生成,请取消注释下列行,然后保存并生成项目  
  51. // 若要测试此 Web 服务,请按 F5 键  
  52.  
  53. // [WebMethod]  
  54. // public string HelloWorld()  
  55. // {  
  56. // return "Hello World";  
  57. // }  
  58. }  
  59. }  

直接使用“VS2003 Web Service服务示例”,我们先看一下最简单的Web Service是什么样子的。去掉53~58行的注释后(如代码2),直接按F5编译查看效果。

  1. [WebMethod]  
  2. public string HelloWorld()  
  3. {  
  4. return "Hello World";  
  5. }  

【编辑推荐】

  1. 微软员工对于Visual Studio2003代码编辑器的说明
  2. 几分钟让你了解Visual Studio Boost的配置方法
  3. 有力说明Visual Studio调试的相关技巧与策略
  4. 闹心的Visual Studio 2005 SP1的下载安装调试
  5. Visual Studio 2010开发部署64位程序
责任编辑:chenqingxiang 来源: 百度博客
相关推荐

2009-11-26 15:50:06

VS2003编译器

2009-11-30 16:50:26

VS2003调试

2009-11-27 16:25:54

2009-11-30 13:51:28

2009-11-30 11:05:19

VS2003 WebS

2009-12-01 17:55:11

VS2003配置

2009-11-30 17:28:39

VS2003 ASP

2009-12-01 15:32:48

VS2003配置

2009-11-27 10:03:48

VS2003安装失败

2009-11-30 10:34:28

VS2003编译

2009-11-25 13:35:05

VS2003使用

2009-11-30 13:51:28

VS2003 Acti

2009-11-30 13:51:28

ActiveX控件

2009-11-27 16:16:51

VS2003系统

2009-11-26 11:05:59

VS2003控件

2009-11-30 10:07:19

VS2003版本

2009-11-26 08:57:01

VS2003发布

2009-11-26 14:10:08

2009-11-27 09:16:11

VS2003配置文件

2009-11-26 13:55:35

VS2003源代码
点赞
收藏

51CTO技术栈公众号