下面代碼中標記的行(//這是異步調用)。不會叫異步調用回來,如果我在這個值傳遞作爲查詢到我的功能:等號登錄數據「導致」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("&", "&");
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);
}
}
內容*可能影響結果,例如,如果你在文本中有一個非轉義的'<' or '>',但我不明白爲什麼'='會成爲一個問題。嘗試在Internet Explorer中加載XML,看看它是否抱怨。 –
但我只請求一個不執行查詢的流。所以查詢甚至在掛起之前還沒有通過連接發送。 – Man
@EricJ。 Internet Explorer不會抱怨等號。 – Man