Advertisement
Guest User

Untitled

a guest
Feb 20th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. namespace AuthenticateWCF
  2. {
  3. public class CustomUserNameValidator : System.IdentityModel.Selectors.UserNamePasswordValidator
  4. {
  5.  
  6. public override void Validate(string userName, string password)
  7. {
  8. if (userName == null && password == null)
  9. throw new ArgumentNullException();
  10.  
  11. if (!(userName == "rrr" && password == "ppp"))
  12. throw new FaultException("incorrect password");
  13.  
  14.  
  15. }
  16. }
  17. }
  18.  
  19. <system.serviceModel>
  20. <behaviors>
  21. <serviceBehaviors>
  22. <behavior>
  23. <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
  24. <serviceDebug includeExceptionDetailInFaults="false"/>
  25. <serviceCredentials>
  26. <userNameAuthentication userNamePasswordValidationMode="Custom"
  27. customUserNamePasswordValidatorType="AuthenticateWCF.CustomUserNameValidator, AuthenticateWCF"/>
  28. </serviceCredentials>
  29. </behavior>
  30. </serviceBehaviors>
  31. </behaviors>
  32. <bindings>
  33. <basicHttpBinding>
  34. <binding name="SecureBasic">
  35. <security mode="TransportWithMessageCredential">
  36. <message clientCredentialType="UserName"/>
  37. </security>
  38. </binding>
  39. <binding name="wsHttp">
  40. <security mode="TransportWithMessageCredential">
  41. <message clientCredentialType="UserName" />
  42. </security>
  43. </binding>
  44. </basicHttpBinding>
  45. </bindings>
  46. <protocolMapping>
  47. <add binding="basicHttpBinding" scheme="http" />
  48. </protocolMapping>
  49. <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  50. </system.serviceModel>
  51.  
  52. ServiceReference1.Service1Client _client = new ServiceReference1.Service1Client();
  53.  
  54. _client.ClientCredentials.UserName.UserName = "a";
  55. _client.ClientCredentials.UserName.Password = "bb";
  56.  
  57. var result = _client.GetData(5);
  58.  
  59. <binding name="BasicHttpBinding_IService1" >
  60. <security mode="TransportWithMessageCredential">
  61. <message clientCredentialType="UserName"/>
  62. </security>
  63. </binding>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement