WCF REST RequestInterceptor认证 [英] WCF REST RequestInterceptor authentication
问题描述
我试图做一个WCF RequestInterceptor一些基本的身份验证。我使用这篇文章作为一个开始。
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 [Htt的prequestMessageProperty.Name] [富] =值
- 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;
}
}
我的问题是:
-
我怎样才能通过拦截和服务之间的数据?
How can I pass data between the Interceptor and the service?
有没有通过他们之间的身份验证信息的方式canoncial(注意,该验证信息是在数据库中,而不是Windows标识一个UID)?
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)?
感谢
推荐答案
您与您的拦截器创建SecureWebServiceHostFactory?
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;
}
}
我用这个例子和它的作品,仔细看看你的code,你可能会失去了一些东西。
I have used that example and it works, take a closer look to your code, you might be missing something.
这篇关于WCF REST RequestInterceptor认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!