【转载】在 Visual Studio 2012 中创建 ASP.Net Web Service
2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址:https://cloud.tencent.com/act/cps/redirect?redirect=1062
2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址:https://www.aliyun.com/minisite/goods
推荐:在 Visual Studio 2012 中创建 ASP.Net Web Service
在 Visual Studio 2012 中创建 ASP.Net Web Service,步骤非常简单。如下: 第一步:创建一个“ASP.Net Empty Web Application”项目 创建一个“ASP.Net Empty W
在 Visual Studio 2012 中创建 ASP.Net Web Service,步骤非常简单。如下:
第一步:创建一个“ASP.Net Empty Web Application”项目
创建一个“ASP.Net Empty Web Application”项目。你会看到一个进度条,显示 Visual Studio 2012 正在创建这个空的 ASP.Net Web Application。
经历短暂的等待之后,一个空的 ASP.Net Web Application 就建好了,它仅包含一个站点配制文件(Web.config),其余的什么也没有。
第二步:在项目中添加“Web Service”新项目
在 Visual Studio 2012 的 Solution Explorer 中,选中当前的这个 project,添加新项目(右键菜单:Add --> New Item),选择“Web Service”这种类型:
第三步:编码、运行
添加完Web Service这种 new item 之后,Visual Studio 已经替我们写了个示范的Web方法了:
推荐:在 Visual Studio 2013 中创建 ASP.NET Web 项目(1):概述 - 创建 Web 应用程序项目
注:本文是“在 Visual Studio 2013 中创建 ASP.NET Web 项目”专题的一部分,详情参见 专题导航 。 预备知识 本专题适用于 Visual Studio 2013 及以上版本。 概
直接按快捷键 F5 就可以看到结果:
点击 HelloWorld 这个链接:
点击页面上的 Invoke 按钮:
然后我们改写这段代码,添加我们自己的方法进去:
- namespace WebApplication1
- {
- using System.Web.Services;
- /// <summary>
- /// Summary description for WebService1
- /// </summary>
- [WebService(Namespace = "http://tempuri.org/")]
- public class WebService1 : System.Web.Services.WebService
- {
- [WebMethod]
- public string HelloWorld()
- {
- return "Hello World";
- }
- [WebMethod]
- public int Add(int x, int y)
- {
- return x + y;
- }
- }
- }
运行:
点击 Add 链接,调用我们刚刚自己添加的 Add 函数:
点击页面上的 Invoke 按钮,得到以 XML 格式返回的执行结果:
+
整个过程非常简单、直观。
推荐:在 Visual Studio 2012 中创建 ASP.Net Web Service 转
http://blog.csdn.net/xinyaping/article/details/7993989 转 在 Visual Studio 2012 中创建 ASP.Net Web Service,步骤非常简单。如下: 第一步:创建一个“ASP
相关阅读排行
- 1asp.net发布到IIS中出现错误:处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
- 2[Asp.Net MVC4]验证用户登录实现
- 3检测到在集成的托管管道模式下不适用的ASP.NET设置的解决方法(非简单设置为【经典】模式)。 - CatcherX
- 4asp.net CheckBoxList 取值与勾选,复选框后台控制前台checkbox选中
- 5ASP.NET 3.5 企业级开发