Last post Sep 02, 2012 01:24 PM by CPrakash82
Sep 01, 2012 06:14 AM|Shikha Nechlani|LINK
How to call WCF REST service from MVC 3 controller using current HTTP request ?
Currently, I am trying to use HttpWebRequest as below, but it generates a new request every time, What i want is to use current Http Request to call web service, Is there any way that I can read current cookies from HttpContext and assign it to my new Http
request before calling web service.. :-
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(myURL);
req.Method = "POST";
req.ContentType = "application/json";
string postData = myData;
req.ContentLength = postData.Length;
StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
Your inputs will help ...Thanks in advance.
Sep 01, 2012 05:48 PM|CPrakash82|LINK
It will be always a different request for WCF and you can not use existing HttpRequest, to send the cookies, you can get the cookie from current HttpRequest and copy into another cookie collection and send it with new HttpWebRequest.
Caution- Why your service is dependent on the cookie? Ideally you should not make your service code dependent on cookie, session or Web request.
Sep 02, 2012 06:06 AM|Shikha Nechlani|LINK
Thanks for your reply.
Please can you tell me how can I get the cookie from current HttpRequest and copy into another cookie collection and send it with new HttpWebRequest with some code snippet or any link, so that I can try it....
Sep 02, 2012 01:24 PM|CPrakash82|LINK
You can follow the below steps.