Ho creato un'app in grado di accedere e controllare le telecamere Onvif che funziona abbastanza bene. Tuttavia questa è la prima volta che realizzo qualsiasi app che utilizza richieste web come questa (o del tutto), quindi presumo che stia utilizzando tecniche abbastanza basilari. La parte del codice Sono curioso di sapere è questo:Modi per accelerare le richieste Web?
Uri uri = new Uri(
String.Format("http://" + ipAddr + "/onvif/" + "{0}", Service));
WebRequest request = WebRequest.Create((uri));
request.Method = "POST";
byte[] b = Encoding.ASCII.GetBytes(PostData);
request.ContentLength = b.Length;
//request.Timeout = 1000;
Stream stream = request.GetRequestStream();
//Send Message
XmlDocument recData = new XmlDocument();
try
{
using (stream = request.GetRequestStream())
{
stream.Write(b, 0, b.Length);
}
//Store response
var response = (HttpWebResponse) request.GetResponse();
if (response.GetResponseStream() != null)
{
string responsestring = new
StreamReader(response.GetResponseStream())
.ReadToEnd();
recData.LoadXml(responsestring);
}
}
catch (SystemException e)
{
MessageBox.Show(e.Message);
}
return recData;
}
Il codice funziona bene, ma utilizzando le situazioni WriteLine che ho trovato che la prima richiesta è di circa 400ms per completare mentre quelli successivi prendono solo tra 10 - 20ms. C'è qualcosa che posso fare per accelerare la prima richiesta?
Questo è un buon collegamento. L'impostazione request.Proxy su null dovrebbe aiutare la prima richiesta. –