【发布时间】:2011-11-23 12:43:55
【问题描述】:
这是我的网络服务代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.Sql;
using System.Data.SqlClient;
namespace DBwebService
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://kse.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 WebService1 : System.Web.Services.WebService
{
string ConnectionString = "Data Source=Shumaila-PC;Initial Catalog=kse;Persist Security Info=True;User ID=sa;Password=sa";
public SqlConnection Conn;
[WebMethod]
public void SqlConn()
{
Conn = new SqlConnection(ConnectionString);
// Conn.Open();
}
//catch (SqlException ex)
//{
// //Console.WriteLine( "Connection Unsuccessful " + ex.Message);
//}
}
}
我需要返回我的 sql 连接对象,以便我可以在我的 asp.net pid roject 中调用它。但是当我这样做时
public SqlConnection SqlConn()
和
return.Conn();
这给了我以下错误
“/”应用程序中的服务器错误。解析器错误描述:解析服务此请求所需的资源时发生错误。请查看以下特定的解析错误详细信息并适当地修改您的源文件。
解析器错误消息:无法创建类型“DBwebService.WebService1”。
来源错误:
第 1 行:
源文件:/WebService1.asmx 行:1
版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.0.30319.1 --.元数据包含无法解析的引用:“http://localhost:50387/WebService1.asmx”。内容类型 text/html;响应消息的 charset=utf-8 与绑定的内容类型不匹配(application/soap+xml;charset=utf-8)。如果使用自定义编码器,请确保正确实现 IsContentTypeSupported 方法。响应的前 1024 个字节是:'/'应用程序中的服务器错误。解析器错误'。远程服务器返回错误:(500) 内部服务器错误。如果在当前解决方案中定义了服务,请尝试构建解决方案并再次添加服务引用。
【问题讨论】:
-
这是错字。我已经编码了康恩
标签: asp.net