Reputation: 357
I am new to WCF and now really lost with this problem... I want my WCF Service to authenticate incoming request using the username and password provided by client.
Relevant parts of Web.Config looks like this:
<endpoint name="wsBinding"
address=""
binding="wsHttpBinding"
contract="ServiceLib.IBooking"
bindingConfiguration="myWSSettings"
/>
And...
<bindings>
<wsHttpBinding>
<binding name="myWSSettings">
<security mode="Transport">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType= "ServiceLib.MyCustomUserNameValidator, ServiceLib" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
MyCustomUserNameValidator is just a temporary validator which simply throws Exception if username is not equal to password.
Client program (a console app) is doing this:
BookingClient client = new BookingClient("wsBinding");
Passenger passenger = new Passenger();
// ../
client.ClientCredentials.UserName.UserName = "SomeUserName";
client.ClientCredentials.UserName.Password = "WrongPassword";
// ...
// ...
// NOTE: Following should throw My SecurityException Since username and
// Password are not equal
bool confirmed = client.IsTicketConfirmed(passenger);
This is the error I get:
The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM,Basic
Would really appreciate any help! I have spent tons of time trying to figure this out but in vain.
Thanks Sandeep
Note:--------
Upvotes: 2
Views: 2330
Reputation: 206
You must change security mode to TransportWithMessageCredential :
<wsHttpBinding>
<binding name="SafeServiceConf">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
You will found a good sample here.
Upvotes: 1