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

  • Home
  • SEARCH
  • 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 4110044
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:52:58+00:00 2026-05-20T21:52:58+00:00

I have a custom attribute that I want to apply to each methods in

  • 0

I have a custom attribute that I want to apply to each methods in my WCF service.

I proceed like this:

[MyAttribute]
void MyMethod()
{

}

The problem is that my service contains hundreds of methods and I don’t want to write [Attribute] above all of them. Is there a way to apply the attribute to all my methods in my service?

Here’s my attribute’s signature:

//[AttributeUsage(AttributeTargets.Class)]
public class SendReceiveBehaviorAttribute : Attribute, /*IServiceBehavior,*/ IOperationBehavior

EDIT after Aliostad’s answer:

I tried this:

public void ApplyDispatchBehavior(ServiceDescription desc, ServiceHostBase host)
{
    foreach (ChannelDispatcher cDispatcher in host.ChannelDispatchers)
    {
        foreach (EndpointDispatcher eDispatcher in cDispatcher.Endpoints)
        {
            foreach (DispatchOperation op in eDispatcher.DispatchRuntime.Operations)
            {
                op.Invoker = new OperationInvoker(op.Invoker);
            }
        }
    }
}

And that:

public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
{
    foreach (ChannelDispatcher cDispatcher in serviceHostBase.ChannelDispatchers)
    {
        foreach (EndpointDispatcher eDispatcher in cDispatcher.Endpoints)
        {
            foreach (DispatchOperation op in eDispatcher.DispatchRuntime.Operations)
            {
                op.Invoker = new OperationInvoker(op.Invoker);
            }
        }
    }
}

But it still don’t work.

  • 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-20T21:52:59+00:00Added an answer on May 20, 2026 at 9:52 pm

    According to IServiceBehaviour documentation, if you implement this interface and create an attribute and put it at the class level, it will be applied to all operations:

    Create a custom attribute that
    implements IServiceBehavior and use it
    to mark service classes that are to be
    modified. When a ServiceHost object is
    constructed, uses reflection to
    discover the attributes on the service
    type. If any attributes implement
    IServiceBehavior, they are added to
    the behaviors collection on
    ServiceDescription.


    UPDATE

    Instead of implementing IOperationBehaviour, add required behaviour in the IServiceBehaviour by looping through all operations:

    foreach (EndpointDispatcher epDisp in chDisp.Endpoints)
    {
        epDisp.DispatchRuntime.MessageInspectors.Add(this);
        foreach (DispatchOperation op in epDisp.DispatchRuntime.Operations)
        {
            op.ParameterInspectors.Add(this); // JUST AS AN EXAMPLE 
        }                        
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which is marked with a custom attribute, like this: public
I have a custom filter attribute that I want to use on certain ActionResults
hi i would like to create a custom calendar, this calendar will have custom
I have created a custom Attribute to decorate a number of classes that I
I have a custom attribute, inside the constructor of my custom attribute I want
Let's say I have a file-system that looks a little something like this: C:\stuff\build.xml
I have a viewmodel that partially looks like this... [Required] public int Year {
I have a model that has an attribute that referrers to when this object
Suppose I have a simple XHTML document that uses a custom namespace for attributes:
I have a custom attribute which can be assigned to a class, [FooAttribute] .

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.