Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- User user = new User();
- TextBox userName_txtb = (TextBox)this.Page.FindControl("username");
- user.UserName = userName_txtb.Text;
- TextBox password_txtb = (TextBox)this.Page.FindControl("passwordTextBox");
- user.Password = password_txtb.Text;
- TextBox email_txtb = (TextBox)this.Page.FindControl("email_link");
- user.Email = email_txtb.Text;
- TextBox telephone_txtb = (TextBox)this.Page.FindControl("mobile_number");
- user.Telephone = telephone_txtb.Text;
- TextBox firstName_txtb = (TextBox)this.Page.FindControl("f_name");
- user.Email = firstName_txtb.Text;
- TextBox lastName_txtb = (TextBox)this.Page.FindControl("l_name");
- user.Telephone = lastName_txtb.Text;
- TextBox birthdate_txtb = (TextBox)this.Page.FindControl("birth_date");
- user.Birthdate = birthdate_txtb.Text;
- // ..etc i fill the user object with values from the Registration form
- var webClient = new WebClient();
- DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(User));
- MemoryStream mem = new MemoryStream();
- ser.WriteObject(mem, user);
- string data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
- webClient.Headers["Content-type"] = "application/json";
- webClient.Encoding = Encoding.UTF8;
- try
- {
- // here is where the exception is thrown
- **String str = webClient.UploadString(BASE_URL + "Create", "POST", data);**
- if (str.Equals("false"))
- {
- Session["error"] = "username already exists";
- }
- else
- {
- Session["userId"] = user.UserName;
- Session["login_status"] = "OK";
- }
- }
- catch (WebException ex) {
- printException(ex);
- throw ex;
- }
- [OperationContract]
- [WebInvoke(Method = "POST", UriTemplate = "Create", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
- bool create(UserServiceClass _user);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement