Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. User user = new User();
  2. TextBox userName_txtb = (TextBox)this.Page.FindControl("username");
  3. user.UserName = userName_txtb.Text;
  4. TextBox password_txtb = (TextBox)this.Page.FindControl("passwordTextBox");
  5. user.Password = password_txtb.Text;
  6. TextBox email_txtb = (TextBox)this.Page.FindControl("email_link");
  7. user.Email = email_txtb.Text;
  8. TextBox telephone_txtb = (TextBox)this.Page.FindControl("mobile_number");
  9. user.Telephone = telephone_txtb.Text;
  10. TextBox firstName_txtb = (TextBox)this.Page.FindControl("f_name");
  11. user.Email = firstName_txtb.Text;
  12. TextBox lastName_txtb = (TextBox)this.Page.FindControl("l_name");
  13. user.Telephone = lastName_txtb.Text;
  14. TextBox birthdate_txtb = (TextBox)this.Page.FindControl("birth_date");
  15. user.Birthdate = birthdate_txtb.Text;
  16.  
  17. // ..etc i fill the user object with values from the Registration form
  18.  
  19. var webClient = new WebClient();
  20. DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User));
  21. MemoryStream mem = new MemoryStream();
  22. ser.WriteObject(mem, user);
  23. string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
  24. webClient.Headers["Content-type"] = "application/json";
  25. webClient.Encoding = Encoding.UTF8;
  26.  
  27. try
  28. {
  29. // here is where the exception is thrown
  30. **String str = webClient.UploadString(BASE_URL + "Create", "POST", data);**
  31. if (str.Equals("false"))
  32. {
  33. Session["error"] = "username already exists";
  34. }
  35. else
  36. {
  37. Session["userId"] = user.UserName;
  38. Session["login_status"] = "OK";
  39. }
  40. }
  41. catch (WebException ex) {
  42. printException(ex);
  43. throw ex;
  44. }
  45.  
  46. [OperationContract]
  47. [WebInvoke(Method = "POST", UriTemplate = "Create", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
  48. bool create(UserServiceClass _user);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement