【发布时间】:2010-09-21 05:04:11
【问题描述】:
我是 WCF 新手,我正在尝试在 IIS 上部署我的 WCF 示例应用程序,此应用程序在 VS2008 的调试模式下工作正常,此应用程序使用以下代码验证 WCF 消息。我是这样做的,我已经在wwwroot目录中添加了生成的.dlls web.config和Service.svc,并且我还在IIS管理器中添加了连接字符串,即
Server=MyPC\SQLEXPRESS;Database=MySampleDb;Integrated Security=true
我正在使用 Windows 集成安全性。我在数据库类中使用相同的连接字符串进行连接,但出现以下异常,
请指导我部署此应用程序
在验证器中
public override void Validate(string userName, string password)
{
ValidateUser(userName, password);
}
public static bool ValidateUser(string userName, string password)
{
if (!string.IsNullOrEmpty(userName))
{
ICustomer customer = GetCustomerByUsername(userName);
if (customer ==null)
{
throw new exception("User Not found.");
}
else
{
return true;
}
}
else
{
throw new FaultException("User name is required!");
}
}
public static ICustomer GetCustomerByUsername(string username)
{
try
{
//ConnectionString= "Server=MyPC\SQLEXPRESS;Database=MySampleDb;Integrated Security=true";
OpenConnection();
var cmd = new SqlCommand("GetUserByUsername", _connection) { CommandType = CommandType.StoredProcedure };
cmd.Parameters.Add("Username", username);
connState = _connection.State.ToString();
if (_connection.State == ConnectionState.Closed)
{
OpenConnection();
}
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
ICustomer customer = null;
customer = ExtractCustomerFromDataReader(dr)[0];
dr.Close();
return customer;
}
catch (Exception e)
{
throw new Exception(e.Message + Environment.NewLine + e.StackTrace);
}
finally
{
CloseConnection();
}
}
例外:
ExecuteReader 需要一个打开且 可用的连接。连接的 当前状态是关闭的。在 System.Data.SqlClient.SqlConnection.GetOpenConnection(字符串 方法)在 System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(字符串 方法,SqlCommand 命令)在 System.Data.SqlClient.SqlCommand.ValidateCommand(字符串 方法,布尔异步)在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior 运行行为、 布尔返回流,字符串方法, DbAsyncResult 结果)在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior 运行行为、 布尔返回流,字符串方法) 在 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior 行为,字符串方法)在 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior 行为)在 Aschrafi.MobileZollServer.Services.DatabaseHelper.GetCustomerByUsername(字符串 用户名)在
我认为我在数据库设置或 IIS 管理器的网站设置中遗漏了一些要点。非常感谢在 IIS 中部署 WCF 和验证 WCF 通信的一些教程或文章链接。
提前致谢。
【问题讨论】:
标签: wcf authentication iis-7 database-connection