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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With