相关资料:http://blog.csdn.net/yapingxin/article/details/7331375

具体操作:
1.打开“Microsoft Visual Studio 2010”->“文件”->“新建”->“项目”->“已安装的模板”->“其他语言”->“Visual C#”->“Web”->“ASP.NET 空Web应用程序”。
2.“解决方案”->“MyDataService”工程右击->“增加”->“新建项”->“已安装的模版”->“Visual C#”->“Web”->“Web 服务”。

实例代码:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data.OleDb;
using System.Data;
using System.IO; namespace MyDataService
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
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;
} [WebMethod]
public DataSet SelectSQL()
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=E:\\MyData.mdb");
OleDbCommand cmd = new OleDbCommand("select * from usesr", con);
OleDbDataAdapter oda = new OleDbDataAdapter();
DataSet ds = new DataSet();
DataTable dta = new DataTable();
con.Open();
oda = new OleDbDataAdapter(cmd);
oda.Fill(ds, "usesr");
return ds;
} //
[WebMethod]
public string SelectSQL2()
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=E:\\MyData.mdb");
OleDbCommand cmd = new OleDbCommand("select * from usesr", con);
OleDbDataAdapter oda = new OleDbDataAdapter();
DataSet ds = new DataSet();
DataTable dta = new DataTable();
con.Open();
oda = new OleDbDataAdapter(cmd);
oda.Fill(ds, "usesr");
//
System.Text.StringBuilder strbuilder = new System.Text.StringBuilder();
StringWriter writer = new StringWriter(strbuilder);
ds.WriteXml(writer, System.Data.XmlWriteMode.IgnoreSchema); return strbuilder.ToString(); }
[WebMethod]
public string ExecSQL(string ASQL)
{
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=E:\\MyData.mdb");
OleDbCommand cmd = new OleDbCommand(ASQL, con);
con.Open();
//
int num = Convert.ToInt32(cmd.ExecuteNonQuery());
if (num > )
{
string Astr;
Astr = "成功";
return Astr;
}
else
{
string Astr;
Astr = "失败";
return Astr;
}
}
}
}

VisualStudio2010中创建ASP.Net WebService的更多相关文章

  1. 【转载】在 Visual Studio 2012 中创建 ASP.Net Web Service

    在 Visual Studio 2012 中创建 ASP.Net Web Service,步骤非常简单.如下: 第一步:创建一个“ASP.Net Empty Web Application”项目 创建 ...

  2. php中创建和调用webservice接口示例

    php中创建和调用webservice接口示例   这篇文章主要介绍了php中创建和调用webservice接口示例,包括webservice基本知识.webservice服务端例子.webservi ...

  3. 在 Visual Studio 2013 中创建 ASP.NET Web 项目(0):专题导航 [持续更新中]

    写在前面的话 随着 Visual Studio 2013 的正式推出,ASP.NET 和 Visual Studio Web 开发工具 也发布了各自的最新版本. 新版本在构建 One ASP.NET ...

  4. 在 Visual Studio 2013 中创建 ASP.NET Web 项目(1):概述 - 创建 Web 应用程序项目

    注:本文是“在 Visual Studio 2013 中创建 ASP.NET Web 项目”专题的一部分,详情参见 专题导航 . 预备知识 本专题适用于 Visual Studio 2013 及以上版 ...

  5. Visual Studio 2010中创建ASP.Net Web Service

    转自:http://blog.csdn.net/xinyaping/article/details/7331375 很多人在论坛里说,在Visual Studio 2010中不能创建“ASP.Net ...

  6. (转)在 Visual Studio 2010 中创建 ASP.Net Web Service

    很多人在论坛里说,在Visual Studio 2010中不能创建“ASP.Net Web Service”这种project了,下面跟帖者云云,有的说这是因为微软已经将Web Service整合进W ...

  7. 创建ASP.NET Webservice

    一.WebService:WebService是以独立于平台的方式,通过标准的Web协议,可以由程序访问的应用程序逻辑单元. (1)应用程序逻辑单元:web服务包括一些应用程序逻辑单元或者代码.这些代 ...

  8. 如何在 Azure 中创建 ASP.NET Web 应用

    Azure Web 应用提供高度可缩放.自修补的 Web 托管服务. 本快速入门演示如何将第一个 ASP.NET Web 应用部署到 Azure Web 应用中. 完成后,便拥有了一个资源组,该资源组 ...

  9. 在 Visual Studio 2010 中创建 ASP.Net Web Service

    第一步:创建一个“ASP.Net Empty Web Application”项目 第二步:在项目中添加“Web Service”新项目 第一步之后,Visual Studio 2010会创建一个仅含 ...

随机推荐

  1. SaaS系列介绍之十: SaaS的商业模式

    1 引言 赚钱之道很多,但是找不到赚钱的种子,便成不了事业家.作为职业软件人,我们都寻求使用一种有效而经济的过程来建造一个能够工作的,有用的产品.                            ...

  2. Qt: 内建对话框(各种对话框都有了,且用到了qobject_cast解析sender的技术)

    #include "BuiltinDialog.h" #include <QtGui/QTextEdit> #include <QtGui/QPushButton ...

  3. Git教程之使用GitHub

    我们一直用GitHub作为免费的远程仓库,如果是个人的开源项目,放到GitHub上是完全没有问题的.其实GitHub还是一个开源协作社区,通过GitHub,既可以让别人参与你的开源项目,也可以参与别人 ...

  4. How to learn C++ and find all STL Algorithm reference

    You can find all cpp references on websites: http://zh.cppreference.com/ http://www.cplusplus.com/re ...

  5. Linux内核与根文件系统的关系1

    Linux内核与根文件系统的关系开篇题外话:对于Linux初学者来说,这是一个很纠结的问题,但这也是一个很关键的问题!一语破天机: “尽管内核是 Linux 的核心,但文件却是用户与操作系统交互所采用 ...

  6. Windows 各种计时函数总结

    本文对Windows平台下常用的计时函数进行总结,包括精度为秒.毫秒.微秒三种精度的 5种方法.分为在标准C/C++下的二种time()及clock(),标准C/C++所以使用的time()及cloc ...

  7. Android开发之布局的学习

    FrameLayout-帧布局 实现效果: 代码: <?xml version="1.0" encoding="utf-8"?> <Frame ...

  8. 学习Android之内部类

    java语言允许在类中再定义类,这种在其它类内部定义的类就叫内部类.内部类又分为:常规内部类.局部内部类.匿名内部类和静态嵌套类四种.我们内部类的知识在Android手机开发中经常用到. 一.常规内部 ...

  9. [转载]12款免费与开源的NoSQL数据库介绍

    Naresh Kumar是位软件工程师与热情的博主,对于编程与新事物拥有极大的兴趣,非常乐于与其他开发者和程序员分享技术上的研究成果.近日,Naresh撰文谈到了12款知名的免费.开源NoSQL数据库 ...

  10. WVGA-维基百科

    WVGA是一种屏幕分辨率的规格,其中的W意味宽(wide),长宽比为800×480.与之相关的还有VGA(640×480)和FWVGA(854×480). WVGA并不是16:9比例,而是5:3的显示 ...