2010-07-09 71 views
0

我正在爲WP7開發一個程序,這是一個非常奇怪的問題。首先是背景,我正在開發一個異步使用HttpWebRequest/Response的流式報價應用程序。我也在Fiddler中監控整個事情,以確保一切正確。WP7(Windows Phone 7)和Fiddler HTTP流媒體問題

引號通過始終打開的Http連接進入服務器。登錄工作正常,並提交報價訂閱請求。問題是,我從來沒有得到響應(而不會繼續EndGetResponse),除非我做的兩件事情之一:

1-補發通過提琴手 開放訂閱請求2-通過提琴手的RequestBuilder

提交相同的請求

我想在我的筆記本上運行模擬器這個應用程序,但應用程序沒有工作,我得到了一個協議例外,不過這是一個不同的線程的問題。

任何想法?我認爲這與通過Fiddler傳輸數據有關。我嘗試卸載Fiddler,禁用捕獲,撤消WinInet中的代理設置,但沒有任何工作。這讓我瘋狂,所以你的幫助將不勝感激。

更新:我可以用Twitter的流媒體API重新創建這個。以下是新代碼。只要改變憑據佔位符自己:

MainPage.xaml中:

<phoneNavigation:PhoneApplicationPage 
    x:Class="TestHttpStreaming.MainPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:phoneNavigation="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Navigation" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}"> 

    <Grid x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="*"/> 
     </Grid.RowDefinitions> 

     <!--TitleGrid is the name of the application and page title--> 
     <Grid x:Name="TitleGrid" Grid.Row="0"> 
      <TextBlock Text="MY APPLICATION" x:Name="textBlockPageTitle" Style="{StaticResource PhoneTextPageTitle1Style}"/> 
      <TextBlock Text="page title" x:Name="textBlockListTitle" Style="{StaticResource PhoneTextPageTitle2Style}"/> 
     </Grid> 

     <!--ContentGrid is empty. Place new content here--> 
     <Grid x:Name="ContentGrid" Grid.Row="1"> 
      <Button Content="Test" Height="70" HorizontalAlignment="Left" Margin="163,149,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" /> 
     </Grid> 
    </Grid> 

</phoneNavigation:PhoneApplicationPage> 

MainPage.xaml.cs中:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 
using System.IO; 

namespace TestHttpStreaming 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     public MainPage() 
     { 
      InitializeComponent(); 

      SupportedOrientations = SupportedPageOrientation.Portrait | SupportedPageOrientation.Landscape; 
     } 

     Uri uri = null; 
     HttpWebRequest request = null; 
     byte[] buffer = new byte[1024]; 
     Stream stream = null; 
     private void button1_Click(object sender, RoutedEventArgs e) 
     { 
      uri = new Uri("http://stream.twitter.com/1/statuses/sample.json?delimited=length", UriKind.Absolute); 
      request = (HttpWebRequest)WebRequest.Create(uri); 
      request.Method = "GET"; 
      request.Credentials = new NetworkCredential("[username]", "[password]"); 
      request.BeginGetResponse(new AsyncCallback(this.EndGetResponseStream), null); 
     } 
     void EndGetResponseStream(IAsyncResult result) 
     { 
      try 
      { 
       HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result); 
       stream = response.GetResponseStream(); 
       IAsyncResult iarRead = stream.BeginRead(buffer, 0, 1024, new AsyncCallback(StreamingReadCallBack), null); 
      } 
      finally 
      { 
      } 
     } 
     private void StreamingReadCallBack(IAsyncResult asyncResult) 
     { 
      int read = stream.EndRead(asyncResult); 
     } 
    } 
} 

回答

0

請查看:

  1. 有無您在工具條菜單欄上啓用了流模式?

    2. 您是否已關閉「啓用自動回覆」功能?

希望得到這個幫助。

+0

我已經完成了#1,但我可以在哪裏找到「啓用自動回覆」選項? – TheOsiris 2010-07-09 23:38:19

+0

我剛剛發現它,它默認是禁用的,我從來沒有改變它。 – TheOsiris 2010-07-09 23:38:36

+0

你還在努力解決問題嗎? – 2010-07-10 00:06:09

1

不知道是否有人仍然面臨着這個問題。我有這個問題,並得到固定一旦我設置:

request.AllowReadStreamBuffering = false; 

這是最新的框架。