2013-09-24 62 views
2

下面代碼中標記的行(//這是異步調用)。不會叫異步調用回來,如果我在這個值傳遞作爲查詢到我的功能:等號登錄數據「導致」BeginGetRequeststream失敗

<Verb>get</Verb><ResourceList><CatalogQuery><ItemQueryList><ItemIDList><ID>16-=-cedar-bonsai</ID></ItemIDList><AttributesType>all</AttributesType></ItemQueryList></CatalogQuery> 

注意XML的這一部分:

<ID>16-=-cedar-bonsai</ID> 

不過,如果我轉了等號工作到別的

<Verb>get</Verb><ResourceList><CatalogQuery><ItemQueryList><ItemIDList><ID>16-here-cedar-bonsai</ID></ItemIDList><AttributesType>all</AttributesType></ItemQueryList></CatalogQuery> 

請告訴我真的困惑我的是,查詢的內容應該是絕對有被稱爲上回調沒有影響。對?

下面是代碼

//Get get a item attributes Async 
     public XElement makeAsyncCall(string query,bool create = false,bool resent = false) 
     { 

      ManualResetEvent mre = null; 
      //The results will be stored here; 
      StringBuilder xresults = new StringBuilder() ; 

      sem.WaitOne(); 
      try 
      { 
       query = query.Replace("&", "&amp;"); 
       query = query.Replace("#39;", "apos;"); 

       //If this is not a query that is being sent again append additional info 
       if (!resent) 
       { 
        query = HEADER_TEXT + query + CLOSER_TEXT; 
       } 

       //Concatonate a declaration, header information, the query to be performed, and the closing XML tag. Then convert to a Byte array 
       Byte[] byteData = UTF8Encoding.UTF8.GetBytes(
          new XDocument(
           new XDeclaration("1.0", "utf-8", null), 
           XElement.Parse(query) 
          ).ToString() 
       ); 

       string paddr = POST_ADDRESS_QUERY; 
       if (create != false) 
       { 
        paddr = POST_ADDRESS_CREATION; 
       } 

       //Setup the post connection 
       HttpWebRequest httpWReq = WebRequest.Create(paddr) as HttpWebRequest; 
       httpWReq.Method = "POST"; 
       httpWReq.ContentType = "application/x-www-form-urlencoded"; 
       httpWReq.Proxy = null; 
       httpWReq.ContentLength = byteData.Length; 
       httpWReq.KeepAlive = true; 


       using (mre = new ManualResetEvent(false)) 
       { 


        //THIS IS THE ASYNC CALL 
        httpWReq.BeginGetRequestStream(new AsyncCallback(getRequestStreamAsync), Tuple.Create<HttpWebRequest, byte[], bool, StringBuilder, ManualResetEvent>(httpWReq, byteData, create, xresults, mre)); 
        mre.WaitOne(10000); 
        mre.Close(); 

        //Try again if not exited already. 
        if (xresults.Length == 0) 
        { 
         httpWReq.Abort(); 
         sem.Release(); 
         return makeAsyncCall(query, create, true); 
        } 

        sem.Release(); 
        return XElement.Parse(xresults.ToString(), LoadOptions.PreserveWhitespace); 

       } 
      } 
      catch(Exception ex) 
      { 
       mre.Close(); 
       sem.Release(); 
       throw (ex); 
      } 
     } 
+1

內容*可能影響結果,例如,如果你在文本中有一個非轉義的'<' or '>',但我不明白爲什麼'='會成爲一個問題。嘗試在Internet Explorer中加載XML,看看它是否抱怨。 –

+0

但我只請求一個不執行查詢的流。所以查詢甚至在掛起之前還沒有通過連接發送。 – Man

+0

@EricJ。 Internet Explorer不會抱怨等號。 – Man

回答

0

我發現了什麼導致了問題。回調正在執行,但並沒有導致斷點停止。今天早上我再次嘗試了代碼,並且捕捉到了斷點。我不確定這是否是Visual Studio中的錯誤或未定義的行爲?也許有人在這方面更多地瞭解視覺工作室。

請求通過罰款和接收響應,但後來在我的代碼中,我產生了自己的異常,捕獲它們,拋出它們,然後重試命令。所以它陷入了無限循環。

+1

我有這種情況發生時,在構建過程中Antivirus在我的'pdb'文件上有鎖,所以文件已過期,因此斷點無法工作。 –

+0

有趣的是,我在每次運行調試器時都拒絕刪除「鬼」斷點時遇到了問題。我的解決方案是隻刪除pdb文件並重新啓動。也許這兩個問題是相關的。我不認爲在我的情況下,微軟的安全要件會鎖定文件(儘管我猜它是可能的) – Man

+2

如果你有「鬼」斷點檢查你沒有兩個'.cs'文件,同名,但在不同的文件夾或加載的項目。斷點數據庫只使用斷點所在的文件名和行號,儘管如果右鍵單擊斷點時存在全名,如果在不同文件夾中有兩個具有相同名稱的文件或已加載的項目會斷裂在每個具有相同名稱的文件上。 –