2011-01-30 57 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並且只啓用應用程序真正需要的應用程序,因爲用戶無法理解/接受應用程序是否需要訪問「所有內容」;-)

相關問題