我是新的WCF,我想在IIS上部署我的WCF示例应用程序,这个应用程序在VS2008的debugging模式下工作正常,此应用程序使用以下代码validationwcf的消息。 我正在这样做,我已经在wwwroot目录中添加了生成的.dlls web.config和Service.svc,并且我还在IISpipe理器中添加了连接string,它是
Server = MyPC \ SQLEXPRESS; Database = MySampleDb;集成安全性= true
我正在使用Windows集成安全性。 我在数据库类中使用相同的连接string连接,但我得到以下exception,
请指导我部署此应用程序在Validator公共覆盖无效validation(string用户名,string密码){ValidateUser(用户名,密码); }
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需要一个开放和可用的连接。 连接的当前状态是closures的。 System.Data.SqlClient.SqlConnection.GetOpenConnection(String method)System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method,SqlCommand command)at System.Data.SqlClient.SqlCommand.ValidateCommand(String method,Boolean async)at System.Data.SqlClient.SqlConnection.GetOpenConnection(String method)在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,string方法)上的.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,string方法,DbAsyncResult结果)。 DataSqlClient.SqlCommand.ExecuteReader(CommandBehavior行为,string方法)在System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior行为)在Aschrafi.MobileZollServer.Services.DatabaseHelper.GetCustomerByUsername(string用户名)在
我想我在数据库设置或IISpipe理器的网站设置中缺less一些点。 一些教程或atricle链接在iis的wcf部署和authenticationwcf通信将非常感激。 提前致谢。
集成的安全性意味着连接在执行打开操作的线程的凭证下发生。 通常,线程具有进程凭证,在IIS和WCF的情况下,AppPoolconfiguration的凭证运行为。 如果线程正在模拟(WCF经常出现这种情况),那么该线程将拥有调用者的凭据,并发生约束委派以便与远程数据库服务器进行身份validation。 无论使用什么凭证,都必须信任并允许通过数据库服务器进行连接。
所以你的问题的解决scheme取决于你在做什么,你提供了很多的代码,但不是实际的相关信息。
所有这些在产品文档中都有详细的描述,您不应该在MSDN之后有任何问题: – WCF安全基础知识 – 使用WCF委派和模仿 – WCF安全指南
您不显示您实际打开连接的位置。 它像它closures的lokos。