0

I have a service interface that requires different attributes in different situations. In short there are two options:

[DispatchByBodyElementBehavior]
public interface FooPortType
{
    [OperationContractAttribute(Action = "", ReplyAction = "*")]
    FooResponse GetResponse(FooRequest request);
}

and

public interface FooPortType
{
    [OperationContractAttribute(Action = "FooAction", ReplyAction = "*")]
    FooResponse GetResponse(FooRequest request);
}

I could distinguish between the two using compiler options, but I was wondering if there is some way to do this at runtime, for example based on an option in the config file.

Thanks.

Update I'm trying to solve this by changing the attributes at runtime, but ran into problems there, as well (followup question). I'll update this question as I find out more.

Community
  • 1
  • 1
Miel
  • 3,347
  • 2
  • 26
  • 39
  • This is possible using reflection. See http://stackoverflow.com/questions/51269/change-attributes-parameter-at-runtime It's a hack though. – Thomsen Mar 29 '13 at 10:42
  • You can write your own attribute and implement logic of which attribute to use in it depending for example on option in your config – Alex Ovechkin Mar 29 '13 at 10:45
  • Attributes are compile time constants. You _could_ use reflection to generate the interface at runtime, or simply use two different interfaces. – Oded Mar 29 '13 at 10:53

0 Answers0