views:

105

answers:

1

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;
     }
}

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

A: 

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.

sebastian