【问题标题】:Cant find DispatchOperation by name in WCF Extensibility for GET Request在 GET 请求的 WCF 扩展性中无法按名称找到 DispatchOperation
【发布时间】:2013-04-02 03:09:37
【问题描述】:

我最近遇到了一个让我陷入困境的问题。

我在 WCF 中实现了一个自定义 AuthorizationManager,它首先必须按名称提取操作。 WCF 服务通过 REST 和 SOAP 端点公开,因此我必须检查多个位置以找到我需要继续完成身份验证过程的信息。

一切都很好,我有大约 15-20 个服务运行良好,但我最近遇到了一个问题,我无法使用常规方法提取操作名称。

拉取操作的代码如下:

public class AuthorizationManager : ServiceAuthorizationManager
{
    private ServiceEndpoint _endpoint { get; set; }

    public AuthorizationManager(ServiceEndpoint endpoint)
    {
        _endpoint = endpoint;
    }
    public override bool CheckAccess(OperationContext operationContext, ref Message message)
    {
        var buffer = message.CreateBufferedCopy(Int32.MaxValue);
        message = buffer.CreateMessage();
        var originalMessage = buffer.CreateMessage();


        /*Step 1 - Pull Operation*/
        string action = operationContext.IncomingMessageHeaders.Action ?? OperationContext.Current.IncomingMessageProperties["HttpOperationName"] as string;
        DispatchOperation operation = operationContext.EndpointDispatcher.DispatchRuntime.Operations.FirstOrDefault(o => o.Name == action || o.Action == action);
        Type hostType = operationContext.Host.Description.ServiceType;
        var operationInfo = hostType.GetMethod(operation.Name);


        /*Continue here using operationInfo - but operation is null*/

     }
}

这对于拉取 REST 和 SOAP 端点的正确操作很有用,但现在 action 为空。

服务定义如下:

[ServiceContract]
public interface ICollectionService
{
      [OperationContract]
      [WebGet]
      CollectionResponse  GetCollection()
}

一切似乎都很标准,我只是不明白为什么这与我的其他服务有任何不同。

【问题讨论】:

    标签: c# .net wcf rest wcf-extensions


    【解决方案1】:

    我意识到我没有足够仔细地检查我的服务定义,它使用的是 [WebInvoke] 而不是 [WebGet]。这解决了它。

    【讨论】:

      猜你喜欢
      • 2021-10-24
      • 1970-01-01
      • 2019-05-30
      • 2014-06-07
      • 2019-01-07
      • 2022-11-30
      • 2019-04-22
      • 1970-01-01
      • 2012-03-14
      相关资源
      最近更新 更多