请问如何解决error: identifier out of scope问题?

lucasgoldsmith 2006-05-19 02:07:08
我现在有一个ReturnStockHolding的web services,然后我想在一个web application里调用它,可它给了个error: identifier 'ReturnStockHolding' out of scope给我,请问我应该如何解决?ReturnStockHolding本身没有问题,可以返回数值。

StockHoldingDetail.asmx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using DodoBusinessLib;

namespace StockHoldingDetail
{
/// <summary>
/// Summary description for Service1.
/// </summary>
[WebService(Namespace="http://localhost/StockHolding/")]
public class StockHoldingDetail : System.Web.Services.WebService
{
public StockHoldingDetail()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}

#region Component Designer generated code

//Required by the Web Services Designer
private IContainer components = null;

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}

#endregion

// WEB SERVICE EXAMPLE
// The HelloWorld() example service returns the string Hello World
// To build, uncomment the following lines then save and build the project
// To test this web service, press F5

private OnlineApplication online = new OnlineApplication();
private DataSet stock = new DataSet();

/// <summary>
/// Return Stock Holding Details.
/// </summary>
[WebMethod]
public int ReturnStockHolding(int id, string password, int productid, string database)
{
online.SetDatabase(database);
if ((online.ValidateUser(id, password) && (online.ValidateProduct(productid))))
{
stock = online.SetStockHolding(productid);
return int.Parse(stock.Tables["product"].Rows[0]["qty_in_stock"].ToString());
}
else
return -1;
}
}
}


StockChecking.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DodoBusinessLib;

namespace StockHoldingWebApp
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnSubmit;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.TextBox txtUsername;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox txtProduct;
protected System.Web.UI.WebControls.TextBox txtDatabase;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label lblError;
protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnSubmit_Click(object sender, System.EventArgs e)
{
localhost.StockHoldingDetail shd = new StockHoldingWebApp.localhost.StockHoldingDetail();
int userid = int.Parse(txtUsername.Text);
string password = txtPassword.Text;
int product = int.Parse(txtProduct.Text);
string database = txtDatabase.Text;
int result = 0;

try
{
if (txtUsername.Text!="" && txtPassword.Text!="" && txtProduct.Text!="" && txtDatabase.Text!="")
{
result = shd.ReturnStockHolding(userid, password, product, database);
lblError.Text = result.ToString();
}
else
{
lblError.Text = "Your username or password is not correct, please enter again";
}
}
catch
{
lblError.Text = "Your database is not correctly set, please set it again";
}

}
}
}


当我把try catch拿掉后,我又有以下的错误:
Server Error in '/StockHoldingWebApp' Application.
--------------------------------------------------------------------------------

The request failed with HTTP status 401: Access Denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The request failed with HTTP status 401: Access Denied.

Source Error:


Line 35: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost/StockHolding/ReturnStockHolding", RequestNamespace="http://localhost/StockHolding/", ResponseNamespace="http://localhost/StockHolding/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
Line 36: public int ReturnStockHolding(int id, string password, int productid, string database) {
Line 37: object[] results = this.Invoke("ReturnStockHolding", new object[] {
Line 38: id,
Line 39: password,


Source File: c:\inetpub\wwwroot\StockHoldingWebApp\Web References\localhost\Reference.cs Line: 37

Stack Trace:


[WebException: The request failed with HTTP status 401: Access Denied.]
System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
StockHoldingWebApp.localhost.StockHoldingDetail.ReturnStockHolding(Int32 id, String password, Int32 productid, String database) in c:\inetpub\wwwroot\StockHoldingWebApp\Web References\localhost\Reference.cs:37
StockHoldingWebApp.WebForm1.btnSubmit_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\stockholdingwebapp\stockchecking.aspx.cs:71
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
...全文
416 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
dingxl 2006-10-13
  • 打赏
  • 举报
回复
我也遇到了类似的问题,先支持一下!
我在调试的时候,有两三个局部变量不能查看它的值;如果选定变量后再Add watch,就会在Watch窗口显示:error: identifier 'var' out of scope
哪位大虾遇到过类似情况,请指导一下啊,不胜感激!
ilovejolly 2006-05-20
  • 打赏
  • 举报
回复
mark
lucasgoldsmith 2006-05-20
  • 打赏
  • 举报
回复
是不是要加WEB REFERENCES啊?我已经加过了啊!否则我没法调用的啊!
xiaohutushen 2006-05-19
  • 打赏
  • 举报
回复
你添加web 引用了没有啊。
估计是你的权限有问题。
shalen520 2006-05-19
  • 打赏
  • 举报
回复
HTTP status 401: Access Denied.


访问被拒绝,看下权限设置
BossFriday 2006-05-19
  • 打赏
  • 举报
回复
up

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧