从Web Service检索ASPX页面中的数据 [英] Retrieving Data in a ASPX page from Web Service

查看:80
本文介绍了从Web Service检索ASPX页面中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试使用web服务在.aspx页面中的gridview中检索数据,问题是我无法使用aspx中web服务中定义的方法名称错误是

'WebService'不包含'GetData'的定义,并且没有扩展方法'GetData'接受类型'WebService'的第一个参数可以找到(你是否错过了使用指令或汇编参考?)



我在项目中添加了参考,代码是

ASMX

Hi,
I am trying to retrieve data in gridview in a .aspx page using web service,the problem is that i am not able to use the method name defined in web service in the aspx page.The error is
'WebService' does not contain a definition for 'GetData' and no extension method 'GetData' accepting a first argument of type 'WebService' could be found (are you missing a using directive or an assembly reference?)

I have added the reference in the project, code is
ASMX

using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;


/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 WebService : System.Web.Services.WebService {

    public WebService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public void GetData()
    {
        string cn = ConfigurationManager.ConnectionStrings["connectivity"].ConnectionString;
        using(SqlConnection connection =new SqlConnection(cn))
        {
            SqlCommand command = new SqlCommand("select * from dbo.company",connection);
            SqlDataReader dr = command.ExecuteReader();
            
        }
    
    }
    
}





ASPX页面



ASPX page

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Xml;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Services;

public partial class WebService : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        GridView1.DataSource = web.GetData();
        GridView1.DataBind();
    }

    WebService web = new WebService();
}

推荐答案

检查此链接 Web服务简介:Daily Dilbert [ ^ ]


这篇关于从Web Service检索ASPX页面中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆