I have created a WCF REST service and I am trying to do custom authentication (as it should work on http and https).
I am using custome service authorization manager to check and validate authorization header.
When I call the service using Fiddler and pass Authorization header with request, I am receiving it correctly in the service authorization manager.
But when I am setting credentials on WCFChannelFactory, I am not receiving Authorization header in the service. I expect that authorization header should be created by WCFChannelFactory and passed with request.
Client code is as below:
WebChannelFactory<IDataService> factory = new WebChannelFactory<IDataService>("DataServiceClient1");
factory.Credentials.UserName.UserName = "user1";
factory.Credentials.UserName.Password = "password123";
var client = factory.CreateChannel();
var data = client.GetData1("Microsoft");
Console.WriteLine("Get response : {0}", data);
Client Service Configuration is as below:
<system.serviceModel>
<client>
<endpoint address="http://localhost.fiddler:50179/DataService.svc"
binding="webHttpBinding" bindingConfiguration="auth"
contract="RESTWebServiceSpike.IDataService"
behaviorConfiguration="web"
name="DataServiceClient1">
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="auth">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Basic" />
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
My service Configuration is as below:
<services>
<service name="RESTWebServiceSpike.DataService" behaviorConfiguration="DataServiceBehaviour">
<endpoint address="" binding="webHttpBinding"
contract="RESTWebServiceSpike.IDataService" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DataServiceBehaviour">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true"/>
<serviceAuthorization serviceAuthorizationManagerType="RESTWebServiceImpl.AuthorizationManager, RESTWebServiceImpl" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
I am using custome service authorization manager to check and validate authorization header.