web service in asp.net

我的梦境 提交于 2020-01-17 03:57:48

问题


I want to create an web service for 'sign up' page or database connectivity..

I am done with database connectivity

but i am unable to get how ca i design an sign up page in web service.. as there is no interface in web service.

Please tell me

my web service code is :

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();

        }

    }
}

回答1:


but i am unable to get how ca i design an sign up page in web service.. as there is no interface in web service.

In fact your reasoning is correct. An ASMX web service implements the SOAP protocol and cannot have any GUI interface whatsoever. Top design an interface of a web application in .NET you could use ASP.NET for example. So you could create an ASP.NET application which will consume this web service. By the way ASX web services are considered as deprecated technology and you should use WCF instead.




回答2:


There are different techniques. However, its common to utilize Ajax requests to your webmethod via AJAX.

Here is an older walk-through but its still valid - http://dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx

It demonstrates two approaches using jQuery (which I recommend) and Microsoft Ajax.

Here are some more decent links -

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



来源:https://stackoverflow.com/questions/7477404/web-service-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!