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 7518277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:43:43+00:00 2026-05-30T01:43:43+00:00

I want to be able to authenticate a WCF Rest webservice but I’m not

  • 0

I want to be able to authenticate a WCF Rest webservice but I’m not really sure how to go about it. It looks like many of the other questions relate to stuff in .net 3.5 WCF (such as WebServiceHost2) which no longer seems to exist.

I am wanting to do message based authentication on the WCF service with custom usernames and passwords. From what I can tell this can be done by the following in regular WCF:

<behaviors>
  <serviceBehaviors>
    <behavior name="PasswordValidator">
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom"
                                customUserNamePasswordValidatorType="MyNamespace.PasswordValidator, MyNamespace"/>
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>

however as I am using Rest I cant get this web.config based behaviour config going. I somehow need to do this in my serviceRoute.

RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(HelloService)));

does anyone know how to do this or have any good tutorials on Message Based security with Rest and WCF 4.0?

  • 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-30T01:43:44+00:00Added an answer on May 30, 2026 at 1:43 am

    The way I solved this was to implement a custom authorize attribute which looks at two custom fields which I added into the HTTP headers collection.

    This seems to work pretty well.

    public class UserAndPasswordAuthenticationAttribute : Attribute, IOperationBehavior, IParameterInspector
        {
            public void ApplyDispatchBehavior(
                OperationDescription operationDescription,
                DispatchOperation dispatchOperation)
            {
                dispatchOperation.ParameterInspectors.Add(this);
            }
    
            public void AfterCall(string operationName, object[] outputs,
                                  object returnValue, object correlationState)
            {
            }
    
            public object BeforeCall(string operationName, object[] inputs)
            {
                string username = WebOperationContext.Current
                                       .IncomingRequest.Headers["username"];
                string password = WebOperationContext.Current
                                       .IncomingRequest.Headers["password"];
    
    
                if (username != "bob" || password!= "123")
                {
                    WebOperationContext.Current.OutgoingResponse.StatusCode =
                        HttpStatusCode.Unauthorized;
                    throw new UnauthorizedAccessException("");
                }
    
                return null;
            }
    
            public void AddBindingParameters(OperationDescription operationDescription, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
            {
            }
    
            public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
            {
            }
    
            public void Validate(OperationDescription operationDescription)
            {
            }
        }
    

    I can then just add this attribute to methods in my contract to secure them

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

Sidebar

Related Questions

I want to be able to authenticate a user by using their domain UserId
I want to be able to replicate only the folder structure (not the contents)
I want to be able to authenticate to a website and then access some
I want to be able to securely authenticate users on my site from any
I want to be able to authenticate a user account with youtube from my
I am able to authenticate the user from the database but there are different
I want to be able to authenticate an NT username/password combination through an ASP.NET
I want to develop a java servlet able to authenticate via HTTP protocol on
I want to be able to authenticate then list out all my friends and
I want to be able to customize the :authenticate_user filter to include authenticating a

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.