5

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

casperOne
  • 73,706
  • 19
  • 184
  • 253
user634199
  • 91
  • 2
  • 5

1 Answers1

14

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".

J. Tihon
  • 4,439
  • 24
  • 19