尝试调用我创建的名为pxy.AddCustomer(txtLogin.Text)
的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);
}
}
}
'AuctionService'不包含'AddCustomer'的定义,并且没有扩展方法'AddCustomer'接受类型'AuctionService'的第一个参数(你是否缺少using指令或汇编引用?)
网络服务代码:
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();
}
按钮点击代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="timer/LIB/jquery-2.0.3.js"></script>
<script type="text/javascript" src="timer/jquery.countdownTimer.js"></script>
<link rel="stylesheet" type="text/css" href="timer/CSS/jquery.countdownTimer.css"/>
<script type="text/javascript">
alert("working");
</script>
</head>
<body>
<script type="text/javascript">
alert("tester");
</script>
<div id="main"><span id="m_timer"></span></div>
<script type="text/javascript">
$(function()
{
$("#m_timer").countdowntimer({
minutes : 2‚
size : "lg"
});
})
</script>
</body>
</html>
答案 0 :(得分:0)
Project4WS
和Project4
是两个不同的命名空间。因此,无法在protected void AddCustomer
方法中访问btnNewUser_Click
方法。为public
函数设置访问修饰符AddCustomer
。
答案 1 :(得分:0)
将方法AddCustomer
的访问修饰符从protected更改为public