我做了一个小项目(WCF + REST),我有一个小问题。我想创建我的Authorization和Authentication类。
我的Authorization类:
//validate api key
public class BasicAuthorization : ServiceAuthorizationManager
{
public override bool CheckAccess(OperationContext operationContext,
ref Message message)
{
//some code
}
}我的身份验证类
// validation user login & password
public class BasicAuthentication : ServiceAuthenticationManager
{
public override ReadOnlyCollection<IAuthorizationPolicy> Authenticate(
ReadOnlyCollection<IAuthorizationPolicy> authPolicy, Uri listenUri,
ref Message message)
{
//some code
}
}我也有一些配置文件
<behavior>
<serviceAuthorization
serviceAuthorizationManagerType="WCF.BasicAuthorization, WCF"/>
<serviceAuthenticationManager
serviceAuthenticationManagerType="WCF.BasicAuthentication, WCF"/>
</behavior>类中的代码并不重要--不是问题。
我的问题是如何从operationContext或message类中获取报头。如前所述,我在rest中创建了它,所以我想手动设置Authorizaion头/ www-authenticate头,但应用程序看不到它。
我打开了Fiddler2,并尝试放置任何标题,例如:
Content-Type: application/xml
Authorization: Basic bla23rwerfsd3==
User-Agent: Fiddler
Host: localhost:59305并且message.Headers / operationContext.Headers没有任何my标头(只有另一个),没有授权,没有内容类型
发布于 2011-02-25 21:54:57
您可以在web操作期间使用System.ServiceModel.Web.WebOperationContext类访问标头,该类有一个静态属性"Current",表示当前上下文。它提供了一个包含"WebHeaderCollection“类型的"IncomingRequest”属性的"Header“属性。
https://stackoverflow.com/questions/5117999
复制相似问题