title: Windows Phone 7 - Cookies not sent to WCF service
body: <p>I have a bunch of WCF services at a domain:</p>
  
  <ul>
  <li>AuthenticationService (the standard MS one, over HTTPS)</li>
  <li>AppService (HTTP)</li>
  </ul>
  
  <p>Usually, I call the Authentication Service and a cookie is returned. For desktop applications, I detach the cookie and reattach it with every new service call to the AppService which exposes the meat of my API.</p>
  
  <p>Silverlight in the browser automatically attaches the cookie in all calls to the domain. I expected the phone to do the same.</p>
  
  <p>It doesn't.</p>
  
  <p>Access to the headers is not supported on the phone, so manual manipulation is out. I wonder if its because some bright spark at MS thought that the phone should <em>enforce</em> that cookies are only reattached to HTTPS endpoints at the same domain or something...</p>
  
  <p>Help!!</p>
  
  <p>This is a nightmare to troubleshoot since the phone doesn't support the other major major helpful setting; ignoring self-signed certificates.</p>
  
  <p>Thanks,</p>
  
  <p>Luke</p>
  
  <p>** UPDATE **</p>
  
  <p>While I'm following up the method using CookieContainer I must point out that even though the Add method on the Headers collection is missing in Silverlight, one can still add headers using the indexer.</p>
  
  <p>See <a href="http://cisforcoder.wordpress.com/2010/12/01/how-to-implement-basic-http-authentication-in-wcf-on-windows-phone-7/" rel="nofollow">http://cisforcoder.wordpress.com/2010/12/01/how-to-implement-basic-http-authentication-in-wcf-on-windows-phone-7/</a></p>
  
  <p>** UPDATE 2 **</p>
  
  <p>CookieContainer can be set as per Lex answer. I'm now stuck and continuing to investigate an ArgumentNullException thrown from within the WCF client upon References.cs EndInvoke. My server shows no sign of receiving the call.</p>
  
  <p>Two key calls on the stack are:</p>
  
  <p>System.Net.Browser.HttpWebRequestHelper.ParseHeaders</p>
  
  <p>And</p>
  
  <p>MS.Internal.InternalWebRequest.OnDownloadFailed</p>
  
  <p><strong>FINAL UPDATE</strong></p>
  
  <p>The ArgumentNullException seems to be thrown when called against a server with a self-signed certificate.</p>
  
  <p>However, there's something odd with the emulator/SDK. I have had this exception against all my servers, even those with no SSL, and one with an issued certificate.</p>
  
  <p>I've also had problems that have been resolved only by a local reboot. So I think my problems have been a result of having the right code, but thinking it was wrong because of other problems in the SDK.</p>
  
  <p>Not sure what advice to give, except to be mistrusting of exceptions stemming from the WP7 WCF stack, particularly EndpointNotFoundException and ArgumentNullException, and to have a full framework test client app around as a sanity check.</p>
  
  <p>Luke</p>