若要自定义WCF服务器中的授权,我将重写ServiceAuthorizationManager.CheckAccessCore().。在它中,我需要找到客户端使用OperationContext调用的方法。我在这篇优秀的文章中找到了部分解决方案:WCF: Retrieving MethodInfo from OperationContext
我的案例(简化)如下:
[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);
}
}从上面的帖子获取MethodInfo的代码是:
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);当调用Hello(“杰克”)时,operationContext.IncomingMessageHeaders.Action提供方法名"Hello",而我还需要参数类型来获得正确的方法。(hostType.GetMethod(operation.Name)抛出一个AmbiguousMatchException)
我可以从OperationContext获得参数类型吗?
发布于 2014-03-07 19:05:16
在WCF中,继承的概念仅限于接口,在WCF中不能在服务类级别使用继承的概念。请参阅http://www.codeproject.com/Questions/302481/WCF-Service-Inharitance
https://stackoverflow.com/questions/22256638
复制相似问题