using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
namespace LibraryProgram
{
/// <summary>
/// Summary description for WebService2
/// </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 WebService2 : System.Web.Services.WebService
{
[WebMethod]
public List<string> Getbookname(string bookname)
{
string cs = ConfigurationManager.ConnectionStrings["LibraryDatabaseConnectionString"].ConnectionString;
List<string> booknames = new List<string>();
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("getbookname", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter param = new SqlParameter("@bookname", bookname);
cmd.Parameters.Add(param);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
booknames.Add(rdr["Name"].ToString());
}
return booknames;
}
}
}
}
它显示
中的错误Line 1: <%@ WebService Language="C#" CodeBehind="WebService1.asmx.cs" Class="LibraryProgram.WebService1" %>
但是我无法找到这条线。我可以在哪里找到这条线。请帮助我。我已经看到了这个错误。有人发布了更改代码文件而不是codebehind.but我无法在代码中找到该行。谢谢
答案 0 :(得分:1)
您可能已将默认服务名称从Service1
更改为Service2
。请右键单击.asmx
文件并选择“查看标记”进行检查,它会显示标记为: -
<%@ WebService Language="C#" CodeBehind="Service.asmx.cs" Class="Service.Service1" %>
将其更改为: -
<%@ WebService Language="C#" CodeBehind="Service.asmx.cs" Class="Service.Service2" %>
请注意我使用了虚拟命名空间&amp;这里的服务名称,实际名称必须不同。