Making web service calls with WCF client + cookies
.net, authentication, c#, cookies, wcf
Solution
To add a Cookie header to the WCF request in the current context given that you have the cookie string already:
var prop = new HttpRequestMessageProperty();
prop.Headers.Add(HttpRequestHeader.Cookie, sharedCookie);
OperationContext.Current.OutgoingMessageProperties.Add(HttpRequestMessageProperty.Name, prop);
Problem
Been implementing the `Basic security Authentication` in a `WCF Service.` Managed to get the `.ASPXCookie` from the web service. But, how to pass along the received cookie back to the next request? ``` var authClient = new MovieDbClient(); using (new OperationContextScope(authClient.InnerChannel)) { isValid = authClient.Login("userName", "passWord*"); if (isValid) { var response = (HttpResponseMessageProperty)OperationContext.Current.IncomingMessageProperties[HttpResponseMessageProperty.Name]; sharedCookie = response.Headers["Set-Cookie"]; } } ``` I tried to print the `SharedCookie` and was successful in it. It looks something like, ``` ".ASPXAUTH=E499CA76EAC178A96BE5CA1E314CC90E0A6F9B95AD221EF5AD7D43598E701DC034D40904DBB8ECFBFB3EA21F2597D3C8DAB9B19A0491FD5858E9F0A4B6DC6E6A980FBB4CCADE191855A029CF8236C6890BEE28665C236992632807D1021AA138; expires=Tue, 07-Jan-2014 06:22:22 GMT; path=/; HttpOnly" ``` The question is `how do I pass this cookie information in my next request using wCF Client - authClient` ?