2011-01-30 58 views
6

我正在尝试使用Windows Phone 7仿真器对Huddle API进行身份验证。但是,我没有取得任何成功。我不断收到“远程服务器返回错误:NotFound”。我甚至尝试过“贬低”我的代码,只是尝试一个直接的网站,例如。谷歌,但仍然得到相同的结果。HttpWebRequest在Windows Phone 7上返回“远程服务器返回错误:NotFound”

我有以下代码:

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) => 
    { 
    Dispatcher.BeginInvoke(
    () => 
    { 
    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 
); 

执行总是在闭锁段结束。然而,在观看Fiddler2之后,google.com似乎没有任何流量。所以这个请求似乎没有被做出来。

我在这里看到过类似的问题Retrieve XML from https using WebClient/HttpWebRequest - WP7,但我使用的是标准端口,所以不确定这是相关的。我也尝试按照帖子简化代码,但没有成功。

有趣的是,最可能的选择似乎是因为我可能没有我的AppManifestWM.xaml文件按HttpWebRequest Breaks On WP7定义网络功能,但我AppManifestWM.xaml文件似乎有这样的定义:

<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2009/deployment" AppPlatformVersion="7.0"> 
    <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"> 
    <IconPath IsRelative="true" IsResource="false">ApplicationIcon.png</IconPath> 
    <Capabilities> 
     <Capability Name="ID_CAP_NETWORKING" /> 
     <Capability Name="ID_CAP_LOCATION" /> 
     <Capability Name="ID_CAP_SENSORS" /> 
     <Capability Name="ID_CAP_MICROPHONE" /> 
     <Capability Name="ID_CAP_MEDIALIB" /> 
     <Capability Name="ID_CAP_GAMERSERVICES" /> 
     <Capability Name="ID_CAP_PHONEDIALER" /> 
     <Capability Name="ID_CAP_PUSH_NOTIFICATION" /> 
     <Capability Name="ID_CAP_WEBBROWSERCOMPONENT" /> 
    </Capabilities> 
    <Tasks> 
     <DefaultTask Name ="_default" NavigationPage="MainPage.xaml"/> 
    </Tasks> 
    <Tokens> 
     <PrimaryToken TokenID="xxx.WindowsPhone7.ClientToken" TaskName="_default"> 
     <TemplateType5> 
      <BackgroundImageURI IsRelative="true" IsResource="false">Background.png</BackgroundImageURI> 
      <Count>0</Count> 
      <Title>xxx.WindowsPhone7.Client</Title> 
     </TemplateType5> 
     </PrimaryToken> 
    </Tokens> 
    </App> 
</Deployment> 

所以我很茫然。该请求实际上并没有发生,导致我认为东西正在阻止它。

更新:

没有什么改变,但认为该堆栈跟踪可能HEKO:

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.<>c__DisplayClass2.<>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& stackMark) at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& 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& pResult)

状态是System.Net.WebExceptionStatus.UnknownError

感谢您的时间。

回答

1

好吧,我已经解决了它......但不知道怎么办。我的机器没有重新启动,我的代码没有改变。唯一可能的解释是我的模拟器确实崩溃了几次。也许在那里。

感谢您的时间,这是我使用的代码,这与跨栏API效果很好:你已经提琴手运行

   string url = "https://api.huddle.net/v1/xml/workspaces"; ; 

       HttpWebRequest client= WebRequest.CreateHttp(new Uri(url)) as HttpWebRequest; 

       client.Credentials = new NetworkCredential(ViewModel.UserAccount.UserName, ViewModel.UserAccount.Password); 
       client.AllowReadStreamBuffering = true; 

       // Call and handle the response. 
       client.BeginGetResponse(
        (asResult) => 
        { 
         Dispatcher.BeginInvoke(
          () => 
          { 
           try 
           { 
            var response = client.EndGetResponse(asResult); 
            System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream()); 
            string responseString = reader.ReadToEnd(); 



                     } 
           catch (WebException failure) 
           { 
            MessageBox.Show(failure.Message, "Cannot authenticate", MessageBoxButton.OK); 
#if DEBUG 
            throw failure; 
#endif 
           } 
          }); 
        }, 
         null 
       ); 
0

这可能只是解决您的网络连接问题。

你能通过IE浏览器和应用程序内的WebBrowser控件访问网页吗?

您可能有一个代理方式。看看这个doco在这方面是否有所帮助。

Proxy Support for Windows Phone Emulator

+0

谢谢,米克。我已经尝试过操作系统中的IE“小程序”,这是可行的。也添加了WebBrowser控件到同一页面,这也很好。据我所知,我没有使用代理服务器。 – 2011-01-30 09:26:36

2

做什么?当Fiddler连接到我的网络堆栈时,我重复出现此错误。随着小提琴手关闭,没有问题。

我会有兴趣听到为什么背后,如果有人知道......

干杯

+0

有趣的一点。我现在不记得了。我肯定会有一点,但在失败的时候,我不能说。 – 2012-02-15 15:01:41

3

我工作了几个小时,症状与原始海报完全相同。然后我按照上面的建议关闭了Fiddler2。然后它工作。没有更多“远程服务器返回并且错误:NotFound。”

魔法!谢谢你,凯利布。应该有upvoted但我没有足够的信用。

2

关闭Fiddler2解决了我的问题。

+0

谢谢!从来没有想过这可能是... – Thomas 2014-01-11 18:38:37

6

没用过Fiddler2,但有开发的Windows Phone应用程序时精确同样的问题

对我来说原因很不一样: WMAppManifest.xml只是缺少ID_CAP_NETWORKING!

因为我得到了“没有发现”异常而不是“不支持例外”我几乎尝试了一切,直到我找到了问题的真正原因... ;-)

我宁愿禁用所有CAPS并且只启用应用程序真正需要的应用程序,因为用户无法理解/接受应用程序是否需要访问“所有内容”;-)

相关问题