Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. public class AuthHeader : SoapHeader
  2. {
  3. public string Username;
  4. public string Password;
  5.  
  6. }
  7.  
  8. public class Service1 : System.Web.Services.WebService
  9. {
  10. public AuthHeader Authentication; ** where does visual studio append value to proxy
  11.  
  12. [SoapHeader("Authentication", Required = true)]
  13. [WebMethod]
  14. public string security()
  15. {
  16. if (Authentication.Username == "test" &&
  17. Authentication.Password == "test")
  18. {
  19. return "authenticated";
  20. }
  21. else
  22. {
  23. return "get lost";
  24. }
  25. }
  26.  
  27. static void Main(string[] args)
  28. {
  29. ServiceReference1.AuthHeader auth = new ServiceReference1.AuthHeader();
  30. auth.Username = "test";
  31. auth.Password = "test";
  32.  
  33. ServiceReference1.Service1SoapClient ser = new ServiceReference1.Service1SoapClient();
  34. ser.AuthHeaderValue = auth; ** does not reconise authheadervalue
  35. String message = ser.security();
  36. Console.WriteLine(message);
  37.  
  38. }
  39.  
  40. WebService service = new WebService();
  41. service.Authentication.Username = "a";
  42. service.Authentication.Password = "a";
  43. string str = service .CheckAuthn();
  44.  
  45. public ServiceAuthHeader Credentials;
  46. public class ServiceAuthHeader : SoapHeader
  47. {
  48. public string Username;
  49. public string Password;
  50. }
  51.  
  52. public static string Validate(ServiceAuthHeader soapHeader)
  53. {
  54. string error_msg = "Pass";
  55. if (soapHeader == null)
  56. {
  57. error_msg = "No soap header was specified.";
  58. }
  59. else if (soapHeader.Username == null || soapHeader.Username == "")
  60. {
  61. error_msg = "Username was not supplied for authentication in SoapHeader.";
  62. }
  63. else if (soapHeader.Password == null || soapHeader.Password == "")
  64. {
  65. error_msg = "Password was not supplied for authentication in SoapHeader.";
  66. }
  67.  
  68. else if (soapHeader.Username != "test" || soapHeader.Password != "test")
  69. {
  70. error_msg = "Please pass the proper username and password for this service.";
  71. }
  72.  
  73. return error_msg;
  74. }
  75.  
  76. public static void AuthValidatoin(WebserviceObject callwebservice)
  77. {
  78. ServiceAuthHeader serviceAuthHeaderValue = new LocalERPWebService.ServiceAuthHeader();
  79. serviceAuthHeaderValue.Username = "test";
  80. serviceAuthHeaderValue.Password = "test";
  81. callwebservice.ServiceAuthHeaderValue = serviceAuthHeaderValue;
  82. }
  83.  
  84. WebserviceObject CallWebService = new WebserviceObject();
  85. common.AuthValidatoin(CallWebService);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement