holthelper
New Member
I have a WCF Rest Service, and I am trying to call this from an aspx page on the same website (i.e. both rest and website are on the same website) . I need to keep the session active. the following is happening
If I do not pass the session cookie, The service creates a different session. If I pass the Session cookie, the httpwebrequest takes a long time and then gives a timeout.
Is there something I am doing wrong? Or Perhaps there is a better way to call a REST service whilst keeping the same session of the calling asp.net page. I have the following Rest Signature:\[code\] [OperationContract()] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] string GetFilterQuery(LookupRequestDTO request);\[/code\]From code-behind I am calling this service as follows:\[code\] HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest; req.Method = "POST"; req.Credentials = CredentialCache.DefaultNetworkCredentials; string result = null; req.ContentType = "application/json"; req.Referer = this.Page.Request.Url.AbsoluteUri; var cookieContainer = new CookieContainer();//pass session state; cookieContainer.Add(new Cookie() { Domain = req.RequestUri.Host, Name = "ASP.NET_SessionId", Value = http://stackoverflow.com/questions/14425075/HttpContext.Current.Session.SessionID }); req.CookieContainer = cookieContainer; string data = null; //code that populates data goes here ... (excluded for simplification) using (Stream webStream = req.GetRequestStream()) using (StreamWriter requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII)) { requestWriter.Write(data); } using (HttpWebResponse resp = req.GetResponse() //timeout occurs here as HttpWebResponse) { StreamReader reader = new StreamReader(resp.GetResponseStream()); }\[/code\]the service works correctly and keeps same session when called from javascript using $.ajax approach
If I do not pass the session cookie, The service creates a different session. If I pass the Session cookie, the httpwebrequest takes a long time and then gives a timeout.
Is there something I am doing wrong? Or Perhaps there is a better way to call a REST service whilst keeping the same session of the calling asp.net page. I have the following Rest Signature:\[code\] [OperationContract()] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] string GetFilterQuery(LookupRequestDTO request);\[/code\]From code-behind I am calling this service as follows:\[code\] HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest; req.Method = "POST"; req.Credentials = CredentialCache.DefaultNetworkCredentials; string result = null; req.ContentType = "application/json"; req.Referer = this.Page.Request.Url.AbsoluteUri; var cookieContainer = new CookieContainer();//pass session state; cookieContainer.Add(new Cookie() { Domain = req.RequestUri.Host, Name = "ASP.NET_SessionId", Value = http://stackoverflow.com/questions/14425075/HttpContext.Current.Session.SessionID }); req.CookieContainer = cookieContainer; string data = null; //code that populates data goes here ... (excluded for simplification) using (Stream webStream = req.GetRequestStream()) using (StreamWriter requestWriter = new StreamWriter(webStream, System.Text.Encoding.ASCII)) { requestWriter.Write(data); } using (HttpWebResponse resp = req.GetResponse() //timeout occurs here as HttpWebResponse) { StreamReader reader = new StreamReader(resp.GetResponseStream()); }\[/code\]the service works correctly and keeps same session when called from javascript using $.ajax approach