WCF 4.0类似于WCF REST入门套件的RequestInterceptor?

pyo*_*yon 4 wcf wcf-rest-starter-kit

WCF 4.0是否有模拟类/模块/ WCF REST Starter Kit的RequestInterceptor?

sha*_*ggy 7

我回来了一个更新.

我碰巧重视代码中的简单性,在成功解决了这个问题之后,我不能说我更喜欢它,而不是查询字符串方法.将一个调用放入调用AuthN方法和Aut​​hZ方法的每个服务端点似乎比某些人想象的要容易.

无论如何,足够的意见......对解决方案.我们在这个链接上的解决方案正好在Stackoverflow上,但在我们的上下文中没有很好地描述...所以我将在这里找到示例代码的"user634119":LiveContext中的 标题

首先,我们需要在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>
Run Code Online (Sandbox Code Playgroud)

接下来创建一个类(在上面的serviceBehaviors块中引用称为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
    }
}
Run Code Online (Sandbox Code Playgroud)

接下来制作一个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
    }
}
Run Code Online (Sandbox Code Playgroud)

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