zoukankan      html  css  js  c++  java
  • Web Services创建、部署、发布

    http://blog.csdn.net/hualusiyu/article/details/7920614

    . Net 中 WebServices 的实战

    下面呢,就来具体看看在 . Net 中如何开发一个 WebServices 以及如何使用这个 WebServices

    开发环境:

    Windows 7 下 IIS 7.5

    Visual Studio Team System 2008

    Sql Server 2008

    首先来看看如何开发一个 WebServices

    先建立一个 ASP.NET 应用程序项目,然后再在项目中添加一个 WebServices 服务,

    image

    然后就是在这个 WebServiceTest 中编写业务逻辑了,

    本次实例的业务逻辑呢就是从数据库“图书馆管理系统”中取出所有的读者的信息。

    WebServiceTest.asmx 中的代码如下

    using System.Web.Services;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web.Configuration;

    namespace WebServiceDemo
    {
        [WebService(Namespace = "
    http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]

        public class WebServiceTest : System.Web.Services.WebService
        {
           
    [WebMethod]
            public DataSet GetAllReader()
            {
               
    DataSet ds = new DataSet();
                string connStr =
                    WebConfigurationManager.ConnectionStrings["DBConnString"].ConnectionString;
                string sqlStr = "SELECT [ReaderID],[ReaderIDType],[ReaderName]," +
                                       "[ReaderSex],[ReaderBirth]" +
                                "FROM [图书馆管理系统].[dbo].[Reader]";
                using (SqlConnection sqlCon = new SqlConnection(connStr))
                {
                   
    using (SqlCommand sqlCom = sqlCon.CreateCommand())
                    {
                        sqlCom.CommandType = CommandType.Text;
                        sqlCom.CommandText = sqlStr;
                       using (SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCom))
                        {
                            sqlDa.Fill(ds);
                        }
                    }
                }
                return ds;
            }
        }
    }

    然后我再在这一个项目 WebServiceDemo 中添加一个页面 Test . aspx

    来实现访问自身应用程序中的 WebServices

    (Test . aspx 和 WebServiceTest . asmx 位于同一应用程序中)

    这个 Test . aspx 呢非常简单,仅仅在上面放了一个 GridView ,然后稍微写点 Code-Behind 就 OK 了,

    其代码如下:

    using System;

    namespace WebServiceDemo
    {
        public partial class Test : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    WebServiceTest test = new WebServiceTest();
                    GridView1.DataSource = test.GetAllReader();
                    GridView1.DataBind();
                }
            }
        }
    }

    再来浏览一下 Test . aspx 页面

    image

  • 相关阅读:
    快速排序
    ​直接插入排序(Straight Insertion Sort)
    希尔排序(Shell Sort)
    直接选择排序(Straight Selection Sort)
    安卓倒计时
    Could not resolve com.android.support:multidex:1.0.2
    黄油刀的配置文件
    黄油刀的配置文件
    Unable to start activity ComponentInfo{com.example.administrator.myapplication/com.example.administrator.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #0: Binary XM
    java禁止实例化的工具类
  • 原文地址:https://www.cnblogs.com/8090sns/p/WerServices.html
Copyright © 2011-2022 走看看