0

To customize authorization in WCF server, I override ServiceAuthorizationManager.CheckAccessCore(). In it I need to locate the method called by client using OperationContext. I found partial solution in this excellent post: WCF: Retrieving MethodInfo from OperationContext

My case (simplified) is as below:

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    void Hello(string name);
}

public Class MyService : IMyService
{
    // this method is not part of service contract
    public void Hello()
    {
        Console.WriteLine("Hello World!");
    }

    public void Hello(string name)
    {
        Console.WriteLine(string.Format("Hello {0}!", name);
    }
}

The code to get MethodInfo from above post is:

string action = operationContext.IncomingMessageHeaders.Action;
DispatchOperation operation = 
    operationContext.EndpointDispatcher.DispatchRuntime.Operations.FirstOrDefault(o =>
        o.Action == action);

Type hostType = operationContext.Host.Description.ServiceType;
MethodInfo method = hostType.GetMethod(operation.Name);

When Hello("Jake") is called, operationContext.IncomingMessageHeaders.Action provides method name "Hello", while I also need the parameter types to get the right method. (hostType.GetMethod(operation.Name) throws an AmbiguousMatchException)

Can I get parameter types from OperationContext?

Community
  • 1
  • 1
sz9
  • 33
  • 6

1 Answers1

0

In WCF the concept of inheritance is limited to interfaces, You can't use the concept of inheritance at service class level in WCF. Please refer http://www.codeproject.com/Questions/302481/WCF-Service-Inharitance

  1. WCF even not allows function overloading directly, so you can happily rely on Action property rather worrying about method/function parameters. Even if you want to use functions with same name with in your service then also you need to give a new name by which it is exposed to clients, using Action decorator/property of "OperationContract". Hope this will help you in resolving your confusion.
Vinay Kumar.o
  • 316
  • 1
  • 10
  • The base class is not a WCF service. It is just a base class of the WCF service class. Since it created misunderstanding, I removed the noise of inheritance from the question. Hopefully now it's clear. – sz9 Mar 07 '14 at 19:28
  • In my scenario, one overloaded method is specified as service operation, while the other is not. I can re-organize the code to avoid overloaded methods in the service class, but it will introduce other complexity that I would rather to avoid it if possible. – sz9 Mar 12 '14 at 14:20