开发者

Headers in OperationContext

开发者 https://www.devze.com 2023-02-13 05:12 出处:网络
I\'d make a little project (WCF 开发者_如何学运维+ REST) and I have a small problem. I want make my Authorization and Authentication class.

I'd make a little project (WCF 开发者_如何学运维+ REST) and I have a small problem. I want make my Authorization and Authentication class.

My Authorization class:

//validate api key
public class BasicAuthorization : ServiceAuthorizationManager
{
    public override bool CheckAccess(OperationContext operationContext, 
        ref Message message)
    {
        //some code
    }
}

My Authenticate class

// validation user login & password
public class BasicAuthentication : ServiceAuthenticationManager
{
    public override ReadOnlyCollection<IAuthorizationPolicy> Authenticate(
        ReadOnlyCollection<IAuthorizationPolicy> authPolicy, Uri listenUri, 
        ref Message message)
    {
        //some code
    }
}

I have too some config file

<behavior>
  <serviceAuthorization 
      serviceAuthorizationManagerType="WCF.BasicAuthorization, WCF"/>
  <serviceAuthenticationManager 
      serviceAuthenticationManagerType="WCF.BasicAuthentication, WCF"/>
</behavior>

The code in class is unimportant - is not a problem.

My problem is how to get Headers from operationContext or message class. How i say before, i make this in rest, so i want manual set Authorizaion header / www-authenticate header, but application doesn't see it.

I turn on the Fiddler2, and try put any header for example :

Content-Type: application/xml
Authorization: Basic bla23rwerfsd3==
User-Agent: Fiddler
Host: localhost:59305

And the message.Headers / operationContext.Headers doesn't has any my header (has only other one), no Authorization, no Content-Type


You can access the headers during your web-operation using the System.ServiceModel.Web.WebOperationContext class, which has a static property "Current", which represents the current-context. It provides an "IncomingRequest" property that contains a "Header" property of type "WebHeaderCollection".

0

精彩评论

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

关注公众号