title: HttpWebRequest returning "The remote server returned an error: NotFound" on Windows Phone 7
body: <p>I am trying to authenticate against the Huddle API using the Windows Phone 7 Emulator. However, I am not getting any success. I keep getting "The remote server returned an error: NotFound". I have even tried "dumbing down" my code and just trying a straight web site, eg. Google but still get the same result.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>string url = "http://www.google.com"; 
  
   HttpWebRequest client= WebRequest.CreateHttp(new Uri(url)) as HttpWebRequest;
  
   client.AllowReadStreamBuffering = true;
  
   // Call and handle the response.
   client.BeginGetResponse(
    (asResult) =&gt;
    {
     Dispatcher.BeginInvoke(
      () =&gt;
      {
       try
       {
        var response = client.EndGetResponse(asResult);
        System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream());
        string responseString = reader.ReadToEnd();
  
       }
       catch (WebException failure)
       {
        throw failure;
       }
      });
    },
     null
   );
  </code></pre>
  
  <p>Execution always ends up in the catch section. However, having watched Fiddler2, there seems not to be any traffic at all to google.com. So the request doesn't seem to be being made.</p>
  
  <p>I've seen a similar problem here <a href="https://stackoverflow.com/questions/3457894/retrieve-xml-from-https-using-webclient-httpwebrequest-wp7">Retrieve XML from https using WebClient/HttpWebRequest - WP7</a>, but I am using a standard port so not sure this is relevant. I have also tried simplifying the code as per the post, but no success.</p>
  
  <p>Interestingly, the most likely option seems to be because I may not have Network Capabilities defined in my AppManifestWM.xaml file as per <a href="http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/2a24a9b0-6cf9-480a-930d-866b82a33caf" rel="nofollow noreferrer">HttpWebRequest Breaks On WP7</a>, but my AppManifestWM.xaml file appears to have this defined:</p>
  
  <pre><code>&lt;Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0"&gt;
    &lt;App xmlns="" ProductID="{ac5b5d62-573c-4134-b290-0ad4f678ad7f}" Title="xxx.WindowsPhone7.Client" RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal"  Author="xxx.WindowsPhone7.Client author" Description="Sample description" Publisher="xxx.WindowsPhone7.Client publisher"&gt;
      &lt;IconPath IsRelative="true" IsResource="false"&gt;ApplicationIcon.png&lt;/IconPath&gt;
      &lt;Capabilities&gt;
        &lt;Capability Name="ID_CAP_NETWORKING" /&gt;
        &lt;Capability Name="ID_CAP_LOCATION" /&gt;
        &lt;Capability Name="ID_CAP_SENSORS" /&gt;
        &lt;Capability Name="ID_CAP_MICROPHONE" /&gt;
        &lt;Capability Name="ID_CAP_MEDIALIB" /&gt;
        &lt;Capability Name="ID_CAP_GAMERSERVICES" /&gt;
        &lt;Capability Name="ID_CAP_PHONEDIALER" /&gt;
        &lt;Capability Name="ID_CAP_PUSH_NOTIFICATION" /&gt;
        &lt;Capability Name="ID_CAP_WEBBROWSERCOMPONENT" /&gt;
      &lt;/Capabilities&gt;
      &lt;Tasks&gt;
        &lt;DefaultTask  Name ="_default" NavigationPage="MainPage.xaml"/&gt;
      &lt;/Tasks&gt;
      &lt;Tokens&gt;
        &lt;PrimaryToken TokenID="xxx.WindowsPhone7.ClientToken" TaskName="_default"&gt;
          &lt;TemplateType5&gt;
            &lt;BackgroundImageURI IsRelative="true" IsResource="false"&gt;Background.png&lt;/BackgroundImageURI&gt;
            &lt;Count&gt;0&lt;/Count&gt;
            &lt;Title&gt;xxx.WindowsPhone7.Client&lt;/Title&gt;
          &lt;/TemplateType5&gt;
        &lt;/PrimaryToken&gt;
      &lt;/Tokens&gt;
    &lt;/App&gt;
  &lt;/Deployment&gt;
  </code></pre>
  
  <p>So I'm at a loss. The request doesn't actually seem to be occurring, leading me to think <em>something</em> is preventing it. </p>
  
  <p><em>Update:</em></p>
  
  <p>Nothing changed, but thought this stack trace might heko:</p>
  
  <blockquote>
    <p>System.Net.WebException was unhandled 
    Message=The remote server returned an
    error: NotFound.   StackTrace:
           at System.Net.Browser.ClientHttpWebRequest.InternalEndGetResponse(IAsyncResult
    asyncResult)
           at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult
    asyncResult)
           at xxx.WindowsPhone7.Client.Views.AddHuddleUserPage.&lt;>c__DisplayClass2.&lt;>c__DisplayClass4.b__1()
           at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo
    rtmi, Object obj, BindingFlags
    invokeAttr, Binder binder, Object
    parameters, CultureInfo culture,
    Boolean isBinderDefault, Assembly
    caller, Boolean verifyAccess,
    StackCrawlMark&amp; stackMark)
           at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object
    obj, BindingFlags invokeAttr, Binder
    binder, Object[] parameters,
    CultureInfo culture, StackCrawlMark&amp;
    stackMark)
           at System.Reflection.MethodBase.Invoke(Object
    obj, Object[] parameters)
           at System.Delegate.DynamicInvokeOne(Object[]
    args)
           at System.MulticastDelegate.DynamicInvokeImpl(Object[]
    args)
           at System.Delegate.DynamicInvoke(Object[]
    args)
           at System.Windows.Threading.DispatcherOperation.Invoke()
           at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority
    priority)
           at System.Windows.Threading.Dispatcher.OnInvoke(Object
    context)
           at System.Windows.Hosting.CallbackCookie.Invoke(Object[]
    args)
           at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[]
    args)
           at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr
    pHandle, Int32 nParamCount,
    ScriptParam[] pParams, ScriptParam&amp;
    pResult)</p>
  </blockquote>
  
  <p>The status is <em>System.Net.WebExceptionStatus.UnknownError</em></p>
  
  <p>Thanks for your time.</p>