Windows phone 7 如何使用httpWebRequest和BeginGetRequestStream方法管理超时Windows Phone 7

Windows phone 7 如何使用httpWebRequest和BeginGetRequestStream方法管理超时Windows Phone 7,windows-phone-7,httpwebrequest,timeout,Windows Phone 7,Httpwebrequest,Timeout,我有这个例子,但我想知道如何管理这个例子超时准确。请帮帮我。 提前谢谢 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";

我有这个例子,但我想知道如何管理这个例子超时准确。请帮帮我。 提前谢谢

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
}
public void callREST()
{
Uri=新的Uri(“http://www.domain.com/RestService"); 
HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(uri);
request.Method=“POST”;
request.ContentType=“应用程序/xml”;
BeginGetRequestStream(sendXML_RequestCallback,request);
}
私有void sendXML_RequestCallback(IAsyncResult结果)
{
var req=result.AsyncState作为HttpWebRequest;
字节[]toSign=Encoding.GetEncoding(“ISO-8859-1”).GetBytes(“”);
使用(var strm=req.EndGetRequestStream(结果))
{
标准写入(toSign,0,toSign.Length);
strm.Flush();
}
req.BeginGetResponse(this.fCallback,req);
}
私有void fCallback(IAsyncResult结果)
{
var req=result.AsyncState作为HttpWebRequest;
var resp=请求EndGetResponse(结果);
var strm=resp.GetResponseStream();
//做点什么
}

在Silverlight/Windows Phone 7中,HttpWebRequest不支持超时

您需要创建一个
计时器
,并在启动请求的同时启动它。如果计时器在HWR返回之前触发,则
中止()
请求并假定其超时


有关更多详细信息和示例,请参见:

Yes,但我有两个异步方法,响应分两次完成。也许我应该管理两个计时器?什么方法应该停止计时器?sendXML\u请求回调或fCallback?使用一个计时器。当您满意方法已完成时,停止计时器。这可能是当你得到回应的时候。这取决于您实现超时的目的。