Reputation: 23
I have this example working but I want to know how manage timeout for this example exactly. Please help me. Thanks in advance
public void callREST()
{
Uri uri = new Uri("http://www.domain.com/RestService");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/xml";
request.BeginGetRequestStream(sendXML_RequestCallback, request);
}
private void sendXML_RequestCallback(IAsyncResult result)
{
var req = result.AsyncState as HttpWebRequest;
byte[] toSign = Encoding.GetEncoding("ISO-8859-1").GetBytes("<xml></xml>");
using (var strm = req.EndGetRequestStream(result))
{
strm.Write(toSign, 0, toSign.Length);
strm.Flush();
}
req.BeginGetResponse(this.fCallback, req);
}
private void fCallback(IAsyncResult result)
{
var req = result.AsyncState as HttpWebRequest;
var resp = req.EndGetResponse(result);
var strm = resp.GetResponseStream();
//Do something
}
Upvotes: 2
Views: 3777
Reputation: 65556
Timeout
isn't supported as part of HttpWebRequest in Silverlight / Windows Phone 7.
You'll need to create a Timer
and start that at the same time you start the request. If the timer fires before the HWR returns then Abort()
the request and assume it timed out.
For more details and an example, see: HttpWebRequest Timeout in WP7 not working with timer
Upvotes: 1