繁体   English   中英

asp.net中的Web服务

[英]web service in asp.net

我想为“注册”页面或数据库连接创建一个Web服务。

我已经完成数据库连接

但是我无法获得如何在Web服务中设计注册页面的方法..因为Web服务中没有界面。

请告诉我

我的网络服务代码是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;


namespace WcfService1
{
    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {
        string Connection = "Data Source=SHUMAILA-PC;Initial Catalog=kse;User ID=sa;Password=sa";
        [WebMethod]
        public void SQLconn()
        {
            SqlConnection DataConnection = new SqlConnection(Connection);
            // the string with T-SQL statement, pay attention: no semicolon at the end of //the statement
            string Command = "INSERT INTO login VALUES ('hina','me12')";
            // create the SQLCommand instance
            SqlCommand DataCommand = new SqlCommand(Command, DataConnection);
            // open the connection with our database
            DataCommand.Connection.Open();
            // execute the statement and return the number of affected rows
            int i = DataCommand.ExecuteNonQuery();
            //close the connection
            DataCommand.Connection.Close();

        }

    }
}

但是我无法获得如何在Web服务中设计注册页面的方法..因为Web服务中没有界面。

实际上,您的推理是正确的。 ASMX Web服务实现SOAP协议,并且不能具有任何GUI接口。 在.NET的顶部设计Web应用程序的界面,例如可以使用ASP.NET。 因此,您可以创建一个将使用此Web服务的ASP.NET应用程序。 顺便说一下,ASX Web服务被视为已弃用的技术,您应该改为使用WCF。

有不同的技术。 但是,通过AJAX对Web方法利用Ajax请求是常见的。

这是一个较旧的演练,但仍然有效-http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx

它演示了使用jQuery(我推荐)和Microsoft Ajax的两种方法。

这里有一些更不错的链接-

http://www.asp.net/ajaxlibrary/jquery_dibs.ashx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM