Hello,
I am new with WCF, I am trying to deploy my WCF sample application on IIS, this application works fine in debug mode with VS2008, this application authenticate the WCF messages with following code. I am doing it like this, I have added the resulted .dlls web.config and the Service.svc in the wwwroot directory, and I have also added connection string in IIS Manager, which is
Server=MyPC\SQLEXPRESS;Database=MySampleDb;Integrated Security=true
I am using Windows Integrated Security. I am using same connection string for connection in the database class but I get following exception,
Please guide me to deploy this application
In Validater
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();
}
}
Exception:
ExecuteReader requires an open and available Connection. The connection's current state is closed. at System.Data.SqlClient.SqlConnection.GetOpenConnection(String method) at System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(String method, SqlCommand command) at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) at Aschrafi.MobileZollServer.Services.DatabaseHelper.GetCustomerByUsername(String username) in
I think I am missing some point in database settings or in IIS Manager the website settings. Some tutorial or article link for WCF deployment in IIS and authenticating WCF communication would be really appreciated.
Thanks in advance.