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

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

问题描述:

尝试调用我创建的名为AddCustomer的Web服务方法时出现以下错误。它强调AddCustomer当我做pxy.AddCustomer(txtLogin.Text)不包含定义,也没有扩展方法错误

“AuctionService”不包含“AddCustomer”,没有扩展方法“AddCustomer”接受型“AuctionService”的第一个参数的定义可以找到(是否缺少使用指令或程序集引用)

网络服务代码:

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(); 
    } 
+0

更改方法AddCustomer'的'访问修饰符从'protected'到'方法AddCustomer的访问修饰符public' –

+0

仍然得到同样的错误,当我将其改为公开 – Alex

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

变化,从保护公众