We help IT Professionals succeed at work.
Get Started

Web Services - Client Authentication - C#

Last Modified: 2013-11-25

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;
            return true;

            // if fails authentication
            _isAuthenticated = false;
            return false;

        public string AuthenticatedMethod()
            // method only for authenticated users
            if (!_isAuthenticated)
                return "";

            // authetnciated, retrieve results for given firmID
            string x = "Firm ID Specific Result - " + _firmID.ToString();
            return x;

Suggestions appreciated.
Watch Question
Senior Software Developer
Top Expert 2009
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE