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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:46:59+00:00 2026-06-15T15:46:59+00:00

I have two base classes RequestBase and ResponseBase , for request and response respectively.

  • 0

I have two base classes RequestBase and ResponseBase, for request and response respectively. All types of requsets and response derived from these classes. The RequestBase contains ClientKey and AccessToken fields. Also, I have the AuthenticationService service.

[ServiceContract]
public interface IAuthenticationService
{
   [OperationContract]
   public LoginResponse Login(LoginRequest request);
   ... other methods
}

Suppose we have the OrderService service.

public class OrderService:IOrderService
{       
   public OrderResponse GetOrders(OrderRequest request)
   {
      ...
   }       
}

I need to validate each request for ClientKey and AccessToken, also check whether the user is authenticated. I can do the following:

public OrderResponse GetOrders(OrderRequest request)
{
   var response = new OrderResponse(request.RequestId);
   // call helper method for validation
   var validationResult = ValidateRequest.Validate(request, response, ValidateOptions.All)  
   ...
}  

But I don’t want to write this line of code in every method:

var validationResult = Validate.ValidRequest(request, response, ValidateOptions.All)

What is the best way to do this?

PS. This is Validate method:

public static bool Validate(RequestBase request, ResponseBase response, ValidateOptions validate)
{
   //Validate Client Key. 
   // Hardcoded here.
   if ((Validate.ClientKey & validate) == Validate.ClientKey)
   {
      if (request.ClientKey != "ABC123")
      {
         response.Acknowledge = AcknowledgeType.Failure;
         response.Message = "Unknown Client Key";
         return false;
      }
   }    

   // Validate access token
   if ((Validate.AccessToken & validate) == Validate.AccessToken)
   {
      if (request.AccessToken != _accessToken)
      {
         response.Acknowledge = AcknowledgeType.Failure;
         response.Message = "Invalid or expired AccessToken. Call GetToken()";
         return false;
      }
   }

   // Validate user credentials
   if ((Validate.UserCredentials & validate) == Validate.UserCredentials)
   {
      if (_userName == null) 
      {
         response.Acknowledge = AcknowledgeType.Failure;
         response.Message = "Please login and provide user credentials before accessing these methods.";
         return false;
      }
   }

   return true;
}

One more question: Where is the best place to store _accessToken, _userName on server?

  • 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-06-15T15:47:01+00:00Added an answer on June 15, 2026 at 3:47 pm

    It looks in your case no easy way to achieve what you want. In general you can do some custom things like security validation either on transport level or on WCF level. If your service is hosted in IIS, you can implement custom authentication module, but it’s not your case, since security information is in data contracts. WCF also have several extensibility points, like custom endpoint behaviors, Message Contracts and mentioned by @trydis message inspectors. But they all are not suitable for you out of the box, since it can require taking care on messages serialization and other custom things.
    Better is keep doing this in your code, and if you want to optimize your code, take a look at postsharp.

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

Sidebar

Related Questions

I have a class Derived that inherits directly from two base classes, Base1 and
I have two classes - one base class and one derived from it :
I have two classes, let's say DerivedOne and DerivedTwo, derived from a base class
I have two classes (MVC view model) which inherits from one abstract base class.
I have two classes, one that inherits from the other. The base class is
Let's say we have these two classes: public class Base { public static int
Say we have a class inheriting from two base classes (multiple inheritance). Base class
I have two form classes inheriting from a common base. One of the forms
I have two classes, a base class and a derived class. My base class
I have two classes: a base class, Foo::Base and a derived class, Foo::Base::Sub .

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.