不包含定义,也没有扩展方法错误
本文关键字:扩展 方法 错误 包含 定义 | 更新日期: 2023-09-27 18:17:07
在尝试调用我创建的名为AddCustomer
的web服务方法时出现以下错误。当我执行pxy.AddCustomer(txtLogin.Text)
'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();
}
Project4WS
和Project4
是两个不同的命名空间。所以protected void AddCustomer
方法不能在btnNewUser_Click
方法中被访问。为AddCustomer
函数设置访问修饰符public
将AddCustomer
方法的访问修饰符由protected修改为public