0

Hi i developed a Wcf service using form authentication and there is a login service Method to authenticate the client. This method returns the authentication cookie.

HttpCookie cookie = null;
        returnValue = Membership.ValidateUser(userName, password);
        if (returnValue)
        {
            var ticket = new FormsAuthenticationTicket(
                    1,
                    userName,
                    DateTime.Now,
                    DateTime.Now.AddMinutes(5),
                    true,
                    userName // or user.UserID or other info you might find appropriate
                );
            string encryptedTicket = FormsAuthentication.Encrypt(ticket);
            cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
            HttpContext.Current.Response.Cookies.Add(cookie);

        }
        return returnValue;

All i want to know is how a android client can call this log in service and get the cookie.

I know how to consume using c# as bellow.But i want to do same stuff from a android Mobile.So please give suggestion to the below code from android Version.

 var sharedCookie = string.Empty;
        bool isValid;
        string data = string.Empty;

        var authClient = new LoginServiceClient();
        using (new OperationContextScope(authClient.InnerChannel))
        {
            isValid = authClient.Login("admin1", "outreach#");
            if (isValid)
            {
                var response = (HttpResponseMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name];
                sharedCookie = response.Headers["Set-Cookie"];
            }
        }

        if (isValid)
        {

            var request = (HttpWebRequest)WebRequest.Create("http://localhost:48090/CustomService/GetAgencies");
            request.Headers["Cookie"] = sharedCookie;
            var responce = (HttpWebResponse)request.GetResponse();

            using (var stream = responce.GetResponseStream())
            {
                using (var reader = new StreamReader(stream))
                {
                    data = reader.ReadToEnd();
                }
            }
        }

Please let us know if you need any firther information.

Chandra Mohan
  • 729
  • 2
  • 10
  • 29
  • Maybe same as: http://stackoverflow.com/questions/669764/how-to-consume-wcf-service-with-android – sandkasten May 08 '13 at 07:41
  • I don't think so it is same.Because i want to know how to read that shared cooke in andriod application. Because this wcf service is going to be consumed by andriod client – Chandra Mohan May 08 '13 at 08:02

0 Answers0