I am using the asynchronous read capability of HttpWebRequest, like this:
private void ReadHandler(object userdata)
{
object[] args = (object[])userdata;
HttpWebRequest w = (HttpWebRequest)args[0];
RequestState req = (RequestState)args[1];
IAsyncResult result = w.BeginGetResponse(new AsyncCallback(RespCallback), req);
}
This works fine, unless the requested URL does not exist. If the web server returns "404: Not Found", then the "RespCallback" is called and the call completes.
However, if the web server returns "301: Moved Permanently" then the RespCallback is never called and the Silverlight application modifies the URL and repeats the request forever. The sequence of requests as received by the web server looks like this:
The correct request comes first:
GET /Silverlight/Controls/TripleGauge.xaml?_sldummy=06f631f4-0527-4ec6-875a-013a5c576566 HTTP/1.1
Accept: */*
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Host: developers.cogentrts.com:8088
Connection: Keep-Alive
The first re-request. Notice that the arguments have been stripped and a / added to the URL. This is just plain wrong. The arguments are a necessary part of the URL.
GET /Silverlight/Controls/TripleGauge.xaml/ HTTP/1.1
Accept: */*
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Host: developers.cogentrts.com:8088
Connection: Keep-Alive
Now a second / has been added to the URL and the arguments are still missing.
GET /Silverlight/Controls/TripleGauge.xaml// HTTP/1.1
Accept: */*
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Host: developers.cogentrts.com:8088
Connection: Keep-Alive
All subsequent requests look like the third one. This repeats forever.
Since 301 is a permanent error, why is Silverlight making any repeated calls at all?
Even if you can explain the re-try, why is it stripping the arguments, thereby potentially generating a completely different response page?
Why is it looping forever with the same URL? Isn't the definition of insanity "repeating the same thing over and over, and expecting a different result"?