开发者

Check the properties/behaviors of Service and Operation Contract

What is the method of knowing the properties/behaviors of Operations and Services Programmati开发者_JAVA百科cally.

For example: From an operation I would like to print the AddressFilterMode, ConcurrencyMode etc. of the service, and Impersonation, TransactionAutoComplete, etc. properties of Operation.


You need to obtain get ServiceBehaviorAttribute and DispatchOperation instances and use their properties.

var serviceBehavior = OperationContext.Current.Host.Description.Behaviors.Find<ServiceBehaviorAttribute>();

var operations = OperationContext.Current.EndpointDispatcher.DispatchRuntime.Operations;
string currentOperationAction = OperationContext.Current.IncomingMessageHeaders.Action;
DispatchOperation currentOperation = ( from o in operations
                                       where o.Action == currentOperationAction
                                       select o ).FirstOrDefault();


That method is called Reflection. You will get current type (the service) and you will explore its attributes => you will get for example address filter mode, concurrency mode and instance context mode. You can do the same for operation, service contract, etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜