嘗試調用我創建的名爲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();
}
更改方法AddCustomer'的'訪問修飾符從'protected'到'方法
AddCustomer
的訪問修飾符public' –仍然得到同樣的錯誤,當我將其改爲公開 – Alex