Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4620718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:35:53+00:00 2026-05-22T02:35:53+00:00

Yesterday I began learning WCF by porting an existing ASP.NET Web Service. Creating the

  • 0

Yesterday I began learning WCF by porting an existing ASP.NET Web Service.

Creating the WCF service was very easy in itself. Approximately an hour after I created my first WCF Service Library project ever, I was already successfully testing my new WCF service in the WCF Test Client.

Now I would like to implement a simple authentication system, but still do not know how. For the sake of simplicity, say my Web Service has three operations: logging in, getting the length of the user’s name, and logging out. How do I complete the TODOs in the following code?

[ServiceContract]
public class MyService
{
    [OperationContract(IsInitiating = true, IsTerminating = false)]
    public bool Login(string userName, string password)
    {
        /* I have already implemented the function that validades
           whether the user name and password are correct. */
        if (ValidateLogin(userName, password))
        {
            /* TODO: Initiate a session */
            return true;
        }
        else
            return false;
    }

    [OperationContract(IsInitiating = false, IsTerminating = false)]
    public int GetUserNameLength()
    {
        /*
           TODO: How to validate whether the user has logged in?
                 How to obtain the name of the user that has logged in?
        */
        int userNameLength = 42;
        return userNameLength;
    }

    [OperationContract(IsInitiating = false, IsTerminating = true)]
    public void Logout()
    {
        /* TODO: How to logout? */
    }
}

NOTE: I am the enemy number one of gross hacks. Please lead me towards conceptually “clean” solutions, regardless of their complexity.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:35:53+00:00Added an answer on May 22, 2026 at 2:35 am

    The approach you’re following may not be correct with WCF. Based on your approach above, the user is already authenticated as it’s able to invoke Login operation. Typically, User shouldn’t be allowed to invoke any operation until he/she is auhenticated, but in your approach that’s not the case.

    Also, the sessions in WCF are client initiated, not server initiated. However, based on your approach they seems to be server initiated.

    Here’re some resources which sheds more light on WCF Security,
    http://msdn.microsoft.com/en-us/library/ms731925.aspx
    Improve wcf security guidance – http://wcfsecurityguide.codeplex.com/

    If you want to use Custom UserNamePassword validator, here is the link,
    http://msdn.microsoft.com/en-us/library/aa702565.aspx

    HTH,
    Amit

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday I added a custom MembershipProvider to an ASP.NET web application, but when I
I am new to c#/.net and just switched over to it from classic asp(yesterday).
Yesterday, I began encountering '999' errors on Yahoo-Pipes. It looks like they throttle requests
We've been using VSS 6.0 since time began, but yesterday I nabbed VSS2005 off
I began to use MVVM pattern yesterday.But for working with events i needed to
From yesterday (the first day of US day light saving adjustment had began.) the
I've got an ASP.NET site backed with a SQL Server database. I'm been using
Yesterday I wanted to add a boolean field to an Oracle table. However, there
Yesterday, I asked this question and never really got an answer I was really
Yesterday, I discovered the Subversion (SVN) blame feature, and I was wondering, is this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.