我建了个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();
} }}
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();
} }}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货