WCF 4. 0's analog to WCF REST Starter Kit' s RequestInterceptor?

标签 wcf wcf-rest-starter-kit

WCF 4.0 是否对 WCF REST Starter Kit 的 RequestInterceptor 有一个模拟类/模块/任何东西?

最佳答案

我回来更新了。

我碰巧重视代码的简单性,在成功解决了这个问题之后,我不能说我比 Query String 方法更喜欢它。将单个调用放入调用 AuthN 方法和 AuthZ 方法的每个服务端点似乎比某些人想象的要容易。

无论如何,足够多的意见......关于解决方案。该解决方案就在我们对 Stackoverflow 的关注下,但在我们的上下文中没有很好地描述......所以我将把这里找到的示例代码归功于“user634119”:
Headers in OperationContext

首先,我们需要在 web.config 文件中添加一个 serviceBehavior:

<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceAuthenticationManager serviceAuthenticationManagerType="WCF.BasicAuthorization, WCF"></serviceAuthenticationManager>
      <serviceAuthorization impersonateCallerForAllOperations="false" principalPermissionMode="Custom" serviceAuthorizationManagerType="WCF.BasicAuthentication, WCF">
      </serviceAuthorization>
    </behavior>
  </serviceBehaviors>
</behaviors>

接下来创建一个类(在上面的 serviceBehaviors block 中引用称为 BasicAuthorization):
//Authorize the call against the URI resource being requested...
public class BasicAuthorization : ServiceAuthorizationManager
{
    public override bool CheckAccess(OperationContext operationContext, 
    ref Message message)
    {
        //some code
    }
}

接下来创建一个 Authentication 类:
// Authenticate the header signature as described in my previous post
public class BasicAuthentication : ServiceAuthenticationManager
{
    public override ReadOnlyCollection<IAuthorizationPolicy> Authenticate(
        ReadOnlyCollection<IAuthorizationPolicy> authPolicy, Uri listenUri, 
        ref Message message)
    {
        //some code
    }
}

在 Authenticate 方法中,使用 HttpRequestMessageProperty 提取请求 header 详细信息并执行与我的第一个回复中描述的相同的 3 个步骤。

关于WCF 4. 0's analog to WCF REST Starter Kit' s RequestInterceptor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6023121/

相关文章:

wcf - 错误请求 : WCF REST Service with Starter Kit

Wcf客户端: Passing XML string in the WCF REST service using WebInvoke

c# - 使用 WCF REST 服务入门工具包检索 EF4 POCO

c# - 是否可以通过 Wcftest 客户端测试 WCF throttle 行为?

wcf - 契约(Contract)需要 Session,但 Binding 'BasicHttpBinding' 不支持它或未正确配置以支持它

wcf - 最大接收消息大小 : why both in client and server in a one-way call?

wcf - 如何配置 WCF REST 以使用 SSL?

c# - WCF 服务向客户端发送数据