请大家帮我看看这个could not create type 'service'的问题怎么解决?

chinahero83 chinahero83 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我建了个web service,但是当我点生成网站时,出错信息提示说:could not create type 'service',在网上用百度,谷歌查了很久还是没找到解决办法,请大家帮我看看问题到底出在哪里,代码如下:
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Configuration;
using System.Data.SqlClient;
using System.Diagnostics;

[WebService(Namespace = "http://www.contentmaster.com/NorthwindServices")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {

//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}

/*
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
*/


private void handleWebException(Exception e)
{
EventLog log = new EventLog("Application");
log.Source = "NorthwindServices";
log.WriteEntry(e.Message, EventLogEntryType.Error);
}


[WebMethod]
public decimal HowMuchWillItCost(string productName, int howMany)
{
SqlConnection sqlConn = null;

try
{
ConnectionStringSettings cs =
ConfigurationManager.ConnectionStrings["NorthwindConnectionString"];
string connString = cs.ConnectionString;
sqlConn = new SqlConnection(connString);
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandText = "SELECT UnitPrice FROM Products " +
"WHERE ProductName = '" + productName + "'";
sqlCmd.Connection = sqlConn;
sqlConn.Open();
decimal price = (decimal)sqlCmd.ExecuteScalar();
return price * howMany;
}
catch (Exception e)
{
// Handle the exception
handleWebException(e);
throw new Exception();

}
finally
{
if (sqlConn != null)
sqlConn.Close();
}

}

}
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
chinahero83
Web Services 12,164 成员 16,322 内容