以下のコードでマークされている行 (//THIS IS THE ASYNC CALL)。この値をクエリとして関数に渡すと、非同期コールバックは呼び出されません。
<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);
}
}