Passing a cookie to a wcf service

烈酒焚心 提交于 2019-12-11 07:35:32

问题


I have a bunch of wcf webhttp (rest) services that expect an auth cookie. Question is - How do I pass the formsauth ticket to the wcf service? Flowing authentication works for get requests through the browsers just fine (as it should) but I am not sure how to set the cookie during my calls using httpclient or webchannelfactory. At this point the authentication is done and the cookie is available. I am not sure of where to insert the cookies while invoking the service through a HttpClient.

HttpClient client = new HttpClient();
HttpContent content = 
    HttpContentExtensions.CreateDataContract<EmployeeData>(MyEmployee);
resp = client.Post("http://localhost/someservice", content);

I also tried to use the webchannelfactory as per the following url - http://zamd.net/2009/03/05/flowing-forms-authentication-cookie-to-wcf/

However, var identity = Thread.CurrentPrincipal.Identity as ClientFormsIdentity; returns a null even though the Thread.CurrentPrincipal.Identity is a valid FormsIdentity. Any suggestions would be greatly helpful.

来源:https://stackoverflow.com/questions/5539714/passing-a-cookie-to-a-wcf-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!