0

Ok, here's the problem i've been dealing with the whole day:

I'm building a web application forms using WCF Data Service and XPO as ORM Data Model in the server side which contains a method, and in the client side, i'm trying to add a line to a database from a web form after authenfitication.

The user can log in without problems with this code:

try
            {
                ctx = null;
                ctx = new XpoContext(serviceRootUri);

                ctx.Credentials = new NetworkCredential(UserName.Text, UserPass.Text);
                var res = ctx.Users.FirstOrDefault();

                FormsAuthentication.RedirectFromLoginPage(UserName.Text, Persist.Checked);
            }

            catch (SecurityException ex)
                {
                Msg.Text = "Erreur: " + ex.Message;
                }
         }

now i want to add a line to a database with this code:

Uri u = new Uri(string.Format(LogIn.ctx.BaseUri + "/CreateUser?name='{0}'&pass='{1}'",
            New_UserName.Text, New_UserPass.Text), UriKind.RelativeOrAbsolute);

            LogIn.ctx.Execute(u, "GET");

            ServiceReference1.Users user = new ServiceReference1.Users();
            user.Nom = New_UserName.Text;
            user.Pass = New_UserPass.Text;


            LogIn.ctx.AddToUsers(user);
            LogIn.ctx.SaveChanges();

but after executing in the 1st two lines an exception occurs.

i'm declaring my context as static in the logIn page:

private static Uri serviceRootUri = new Uri("http://localhost:28748/WcfDataService1.svc/");
public static XpoContext ctx;

As u can see i call my context in the adduser web form with LogIn.ctx ( the same context in the log in page )

Thanks

Soufiane N
  • 113
  • 1
  • 11

0 Answers0