我正在尝试在我的webservice中调用一个函数。 相同的技术用于页面上的不同区域,但这似乎不起作用。
这是aspx语法:
<asp:Repeater ID="rptDeleteTickets" runat="server">
<ItemTemplate>
<asp:UpdatePanel ID="DeleteTicketUpdatePanel" runat="server">
<ContentTemplate>
<li>
<asp:Label ID="lblTicketDescD" runat="server" Text='<%# Eval("typ_omschr") %>' /></li>
<li style="border-bottom: 1px solid white;">
<asp:Label ID="lblTicketPriceD" runat="server" Text='<%# Eval("typ_prijs") %>' />
<asp:ImageButton ID="btnDeleteTicket" runat="server" ImageUrl="~/Images/minus.png" Width="20px"
OnCommand="btnDeleteTicket_Command" CommandName='<%# Eval("typ_id") %>' meta:resourcekey="btnDeleteTicketResource1" />
</li>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:Repeater>
btnDeleteTicket_Command
功能:
protected void btnDeleteTicket_Command(object sender, CommandEventArgs e)
{
try
{
String strTypId = e.CommandName.ToString();
int intResult = webService.Festivals_DeleteTicketFestival("1", "3");
divResult.Visible = true;
lblResult.ForeColor = System.Drawing.Color.White;
if (intResult == 1)
{
lblResult.Text = GetLocalResourceObject("SaveSuccess").ToString();
dsTicketsPerFestival = webService.Festivals_GetTicketTypesOfFestival(strFormIdFest);
Session["TicketsPerFestival"] = dsTicketsPerFestival;
}
else if (intResult == -1)
{
lblResult.ForeColor = System.Drawing.Color.LightSalmon;
lblResult.Text = GetLocalResourceObject("ErrorNoDeleted").ToString();
}
else if (intResult > 1)
{
lblResult.Text = GetLocalResourceObject("ErrorMultipleDeleted").ToString();
dsTicketsPerFestival = webService.Festivals_GetTicketTypesOfFestival(strFormIdFest);
Session["TicketsPerFestival"] = dsTicketsPerFestival;
}
}
catch (Exception fatal)
{
divResult.Visible = true;
lblResult.ForeColor = System.Drawing.Color.LightSalmon;
lblResult.Text = GetLocalResourceObject("Error").ToString();
}
}
像这样联系网络服务:
webService.Festivals_DeleteTicketFestival("1", "3");
Festivals_DeleteTicketFestival(String festId, String typId)
功能:
调试时,我可以看到web服务中的festId和typId为空。
[WebMethod]
public int Festivals_DeleteTicketFestival(String festId, String typId)
{
return Festivals_DeleteTicketFestival(festId, typId); //StackOverflowException shown here
}
public int deleteTicketFestival(String festId, String typId)
{
int deletedRows = -1;
try
{
sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["project"].ConnectionString);
sqlCommand = new SqlCommand("DeleteTicketFestival", sqlConnection);
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlAdapter = new SqlDataAdapter(sqlCommand);
sqlCommand.Parameters.Add(new SqlParameter("@festId", festId));
sqlCommand.Parameters.Add(new SqlParameter("@typId", typId));
sqlConnection.Open();
sqlTransaction = sqlConnection.BeginTransaction();
sqlCommand.Transaction = sqlTransaction;
deletedRows = sqlCommand.ExecuteNonQuery();
sqlTransaction.Commit();
}
catch (Exception e)
{
LoggingService.WriteLine(strApplicationName + " Delete festival ticket", e.Message);
if (sqlTransaction != null)
{
sqlTransaction.Rollback();
throw (e);
}
}
return deletedRows;
}
也许有经验丰富的人可以发现这个问题? 谢谢!
答案 0 :(得分:2)
public int Festivals_DeleteTicketFestival(String festId, String typId)
{
return Festivals_DeleteTicketFestival(festId, typId); //StackOverflowException shown here
}
你是在没有结束标准的情况下以递归方式调用相同的函数(事实上,除了在函数中进行此递归调用之外,你不会做任何事情)。这将导致StackOverflowException。
如果您将其更改为
return deleteTicketFestival(festID, TypID)
应该解决涉及此错误的问题。
答案 1 :(得分:1)
您以递归方式打电话给自己,将return Festivals_DeleteTicketFestival(festId, typId);
更改为return deleteTicketFestival(fastId, typId);