开发者

WCF REST RequestInterceptor authentication

I am trying to do some basic authentication in a WCF RequestInterceptor. I am using this article as a start.

The problem I am running into is communicating between the interceptor and the service. Nothing I have tried seems to work. So far, I have tried:

  • OperationContext.Current
  • requestContext.RequestMessage.Properties[HttpRequestMessageProperty.Name]["foo"] = value
  • HttpContext.Current.Request

But no matter what I set, I can't seem to access it in the service behavior itself:

[AspNetCompatibilityRequirements( RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed )]
[ServiceBehavior( InstanceContextMode = InstanceContextMode.Single )]
public class AdvertiserService : ApiServiceBase<AdvertiserDataAccessor>, IAdvertiserService
{
    [WebGet( UriTemplate = "" )]
    public List<Advertiser> GetAdvertisers()
    {
        var request = HttpContext.Current.Request;
        var headers = HttpContext.Current.Request.Headers;
        var p = HttpContext.Current.Request.Headers["Principal"];

        OperationContext ctx = OperationContext.Current;
    开发者_JAVA百科 }
}

My questions are:

  1. How can I pass data between the Interceptor and the service?

  2. Is there a canoncial way to pass auth information between them (note, the auth info is a UID in the database, not a Windows Identity)?

Thanks


Are you creating the SecureWebServiceHostFactory with your Interceptor?

public class SecureWebServiceHostFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
         WebServiceHost2 host = new WebServiceHost2(serviceType, true, baseAddresses);
         host.Interceptors.Add(new AuthenticationInterceptor());
         return host;
     }
}

I have used that example and it works, take a closer look to your code, you might be missing something.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜