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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:05:57+00:00 2026-05-23T14:05:57+00:00

I’m working on some funky code right now, and I’ve been wondering whether or

  • 0

I’m working on some funky code right now, and I’ve been wondering whether or not I can use attributes to modify how a WCF operation behaves, like maybe make it perform additional checking or make it skip some logic.

For example, if we had the following request envelope:

[MessageContract]
public class UserRequest 
{
    [MessageBodyMember]
    public string SessionKey { get; set; }

    [MessageBodyMember]
    public UserModel User { get; set; }
}

and the following service operations:

[ForceSession]
void AddUser ( UserRequest request ) 
{
}

void EditUser ( UserRequest request )
{
}

we could have some automatic functionality on the AddUser operation which checks that the request’s session key exists in the current HttpContext. Maybe something to the equivalent of checking HttpContext.Current.Session[request.SessionKey] != null, to which end it either rejects the call (sends an empty response envelope) or processes it.

Of course, I could just add the checking code at the start of each operation where they matter, but that can get pretty repetitive pretty fast, especially if I’m working with a lot of operations.

How should I go about with implementing something of the sort?

  • 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-23T14:05:57+00:00Added an answer on May 23, 2026 at 2:05 pm

    WCF services use attributes natively just check classes like:

    • ServiceContractAttribute, OperationContractAttribute
    • MessageContractAttriubte, MessageHeaderAttriubte, MessageBodyMemberAttribute
    • WebGetAttribute, WebInvokeAttribute
    • ServiceBehaviorAttribute, OperationBehaviorAttribute, CallbackBehaviorAttriubte
    • ServiceKnownTypeAttribute, FaultContractAttriubte
    • DataContractFormatAttribute, XmlSerializerFormatAttribute
    • TransactionFlowAttribute, DeliveryRequirementsAttribute
    • AspNetCompatibilityRequirementsAttribute
    • and several others

    These attributes affect WCF processing but WCF also offers large extensibility model with several injection points where you can add your own processing by implementing any of these interfaces in custom attribute:

    • IServiceBehavior – affects whole service
    • IEndpointBehavior – affects single endpoint
    • IOperationBehavior – affects single operation
    • IContractBehavior – affects single service or data contract

    These behaviors can contain some logic or add some other more advanced custom features like:

    • IParameterInspector – for example custom parameter validation for operation
    • IDispatchMessageFormater – dealing with serialization and deserialization on server side
    • IClientMessageFormater – dealing with serialization and deserialization on client side
    • IDispatchMessageInspector – message modification or validation on server side
    • IClientMessageInspector – message modification or validation on client side
    • IDispatchOperationSelector – selection of operation handling the incoming message on server side
    • IClientOperationSelector – based on proxy method called can select different operation to be called from the client side
    • IOperationInvoker – invoking the operation – allows working with operation parameters and for example add other parameters which were not passed in the message but are stored locally
    • IErrorHandler – global error handling
    • IInstanceContextProvider – custom instance context handling – the basis if you want to implement custom session handling in WCF
    • IInstanceProvider – custom service instance lifetime handling
    • any many others

    As you can see extensibility of WCF is pretty large – IMHO with ASP.NET MVC the best in the whole .NET framework (at least among parts I’m regularly using). Moreover custom behaviors are only one part of WCF extensibility. The second part deals with custom bindings and channels.

    If you want to know more about WCF extensibility check

    • WCF Extensibility Samples
    • Carlos Figueira’s blog with excellent articles about extensibility

    But is it what you need? First check existing attributes if they already offer you the functionality you are looking for. Next think about session – ASP.NET session is not normally provided to WCF service. You must turn on AspNetCompatibility and after that you will degrade your WCF service to ASMX service. Even after that you can have problems with ASP.NET session because the information about session is transferred in cookie and WCF by default doesn’t use them.

    For last if you only need some custom attributes to add logic to selected methods it more looks like scenario for AoP (aspect oriented programming) which can be offered outside of WCF through several IoC (inversion of control) containers like MS Unity, Windsor Castle or Spring.NET. Another option is pure AoP framework – PostSharp.

    For AoP with Unity you can check several articles by Dino Esposito from MSDN Magazine:

    • Aspect-Oriented Programming, Interception and Unity 2.0
    • Interceptors in Unity
    • Policy Injection in Unity

    For Spring.NET simply check their excellent documentation. I didn’t use AoP with Windsor but you will find plenty of articles on internet. PostSharp is the only mentioned tool which is commercial. It has a free version with smaller feature set but you can find that features you need are only in commercial version.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

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.