I have a WCF service which returns a DataSet and it works just fine. I actually wanted to return a DataTable instead of a DataSet. When I changed the code to return a DataTable and started the service(self-hosted on a console application), it ran and I could see the WSDL document for the servive. However, while consuming the service, I got an error which said:
An error occurred while receiving the HTTP response (along with the service url).
This could be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by the server(possibly due to the service shutting down).
See server logs for more details.
Now, I read somewhere that some other developer had a similar issue on returning a DataTable, which was solved on returning a DataSet. I did the same and was able to solve the issue.
My Question:
However, it does intrigue me as to why did such an issue occur on returning a DataTable? Is there something important related to the basics that I have failed to see ?
The WCF service(with DataTable) has the following code:
public DataTable ValidateLogin(string UserName, string Password)
{
DataTable dt = new DataTable();
LINQHelperDataContext valLog = new LINQHelperDataContext();
var result = from user in valLog.GetTable<USER_DETAILS_T>()
join acctype in valLog.GetTable<Account_type_t>()
on user.UserAccountType equals acctype.AccountTypeId
where user.UserId == UserName
where user.UserPassword == Password
select new {user.UserFirstName,acctype.AccountTypeName };
// select user.UserFirstName;
int rowCount=result.Count();
dt.Columns.Add();
dt.Columns.Add();
if (rowCount == 1)
{
foreach (var res in result)
{
dt.Rows.Add(res.UserFirstName,res.AccountTypeName);
break;
}
return dt;
}
else
{
dt.Rows.Add("Not Found", "Not Found");
return dt;
}
}
}
Following is the code(with DataSet):
public DataSet ValidateLogin(string UserName, string Password)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
LINQHelperDataContext valLog = new LINQHelperDataContext();
var result = from user in valLog.GetTable<USER_DETAILS_T>()
join acctype in valLog.GetTable<Account_type_t>()
on user.UserAccountType equals acctype.AccountTypeId
where user.UserId == UserName
where user.UserPassword == Password
select new {user.UserFirstName,acctype.AccountTypeName };
// select user.UserFirstName;
int rowCount=result.Count();
dt.Columns.Add();
dt.Columns.Add();
if (rowCount == 1)
{
foreach (var res in result)
{
dt.Rows.Add(res.UserFirstName,res.AccountTypeName);
break;
}
ds.Tables.Add(dt);
return ds;
}
else
{
dt.Rows.Add("Not Found", "Not Found");
ds.Tables.Add(dt);
return ds;
}
}
}