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

chinahero83 2009-03-15 06:28:51
我建了个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();
}

}

}
...全文
827 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinahero83 2009-03-16
  • 打赏
  • 举报
回复
其实是我自己添加web配置文件的时候自己不小心选了“移动WEB配置文件”而没选“WEB配置文件”,所以才一直出错,后来我把原来哪个WEB CONFIG删了,重新加了个WEB配置文件进去,就通过了,是我自己太粗心了,还是谢谢大家的帮助了。
chinahero83 2009-03-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jijunwu 的回复:]
没 什么问题】

你在创建服务的时候什么怎么写的?[/Quote]

你好,我看见你你在我贴的另一个版里回了这句,没明白“你在创建服务的时候什么怎么写的?”是什么意思?
chinahero83 2009-03-15
  • 打赏
  • 举报
回复
我也觉得写的没问题,可是一点生成网站,VS就提示说:
错误 1 Could not create type 'Service'. C:\Documents and Settings\hyf\My Documents\Microsoft Press\Visual CSharp Step By Step\Chapter 28\NorthwindServices\App_Data\Service.asmx 1
chinahero83 2009-03-15
  • 打赏
  • 举报
回复
谢谢你给我的网页,其实这个我也看过了。

但是和我的情况还是不一样的,哪个文章里的人都用了namespace,而我的程序里没有namespace,所以在class里补上namespace没法解决我的问题。

另一个人说把<%@ WebService Language="C#" CodeBehind="~/App_Code/Service.cs" Class="Service" %>(service.asmx文件里的)中的~去掉的方法,我也用了,也不管用。
  • 打赏
  • 举报
回复
写的没问题
wuyq11 2009-03-15
  • 打赏
  • 举报
回复
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3914&SiteID=1
charlenchen 2009-03-15
  • 打赏
  • 举报
回复
我也出过这个问题,但我的就是Service.asmx文件没有配置正确造成的,你的就不知道了

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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