不包含定义,也没有扩展方法错误

本文关键字:扩展 方法 错误 包含 定义 | 更新日期: 2023-09-27 18:17:07

在尝试调用我创建的名为AddCustomer的web服务方法时出现以下错误。当我执行pxy.AddCustomer(txtLogin.Text)

时,它下划线AddCustomer

'AuctionService'不包含'AddCustomer'的定义,并且找不到接受'AuctionService'类型的第一个参数的扩展方法'AddCustomer'(您是否缺少using指令或程序集引用?)

web服务代码:

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;
using Utilities;
namespace Project4WS
{
/// <summary>
/// Summary description for AuctionService
/// </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 AuctionService : System.Web.Services.WebService
  {
    [WebMethod]
    public void AddCustomer(String Name)
    {
        SqlCommand objCommand = new SqlCommand();
        objCommand.CommandType = CommandType.StoredProcedure;
        objCommand.CommandText = "AddCustomer";
        objCommand.Parameters.AddWithValue("@theName", Name);
        DBConnect objDB = new DBConnect();
        DataSet myDataSet = objDB.GetDataSetUsingCmdObj(objCommand);            
    }
  }
}

按钮点击代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Project4WS;
namespace Project4
{
public partial class WebForm1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnNewUser_Click(object sender, EventArgs e) 
    {
        AuctionSvcPxy.AuctionService pxy = new AuctionSvcPxy.AuctionService();
        pxy.AddCustomer(txtLogin.Text);
        Session["Customer"] = txtLogin.Text.ToString();
    }

不包含定义,也没有扩展方法错误

Project4WSProject4是两个不同的命名空间。所以protected void AddCustomer方法不能在btnNewUser_Click方法中被访问。为AddCustomer函数设置访问修饰符public

AddCustomer方法的访问修饰符由protected修改为public