I have used .NET Web Services in the past to provide an easy way to access data between applications. In the past, the data being retrieved was never confidential in nature.
I now wish to create Web Service methods for valid, authenticated users of our subscription service. These users have a username, password, and firm ID. I need to accomplish one of the following:
1) Create a Web Service that requires being supplied a username, password and firm id as parameters of every single web method. As soon as the method is called, an authentication check will be performed, and the results will be returned only if the user passes authentication. Additionally, results will only be returned if they are relevant to the "firm id" that is passed.
2) Implement a system where users must authenticate into the web service using their username, password and firm id in a separate method. If they pass authentication, they will be able to make subsequent method calls and have results returned. If not, they will be denied access.
What is the best way to accomplish this?
How is the following example? Does this pose a risk? Is there a better way to proceed?
With the given example, I'm assuming each page will have to reauthetnciate, since _isAuthenticated will be false after the page lifecycle expires?
public class Service1 : System.Web.Services.WebService
private bool _isAuthenticated = false;
private int _firmID = 0;
public bool Authenticate(string user, string pass, int firmID)
// if passes authentication
_isAuthenticated = true;
_firmID = firmID;
// if fails authentication
_isAuthenticated = false;
public string AuthenticatedMethod()
// method only for authenticated users
// authetnciated, retrieve results for given firmID
string x = "Firm ID Specific Result - " + _firmID.ToString();