비동기 호출을 사용하여 웹 서비스에서 데이터를 가져 오는 페이지가 있습니다. webservice에서 응답을 받으면 컨트롤이 메시지 상자의 위치를 파악합니다. 이 코드는 아래와 같습니다 :메시지 상자가 잘못된 페이지에서 팝업 됨
string uri = "http://free.worldweatheronline.com/feed/weather.ashx?key=b7d3b5ed25080109113008&q=Mumbai&num_of_days=5";
UriBuilder fullUri = new UriBuilder("http://free.worldweatheronline.com/feed/weather.ashx");
fullUri.Query = "key=b7d3b5ed25080109113008&q=Mumbai&num_of_days=5";
HttpWebRequest forecastRequest = (HttpWebRequest)WebRequest.Create(fullUri.Uri);
// set up the state object for the async request
ForecastUpdateState forecastState = new ForecastUpdateState();
forecastState.AsyncRequest = forecastRequest;
// start the asynchronous request
forecastRequest.BeginGetResponse(new AsyncCallback(HandleForecastResponse), forecastState);
이 부분은 응답
입니다private void HandleForecastResponse(IAsyncResult asyncResult)
{
try
{
// get the state information
ForecastUpdateState forecastState = (ForecastUpdateState)asyncResult.AsyncState;
HttpWebRequest forecastRequest = (HttpWebRequest)forecastState.AsyncRequest;
// end the async request
forecastState.AsyncResponse = (HttpWebResponse)forecastRequest.EndGetResponse(asyncResult);
Stream streamResult;
string newCityName = "";
//int newHeight = 0;
// get the stream containing the response from the async call
streamResult = forecastState.AsyncResponse.GetResponseStream();
// load the XML
XElement xmlWeather = XElement.Load(streamResult);
}
catch (Exception ex)
{
MessageBox.Show("Connection Error");
}
}
문제 : 이 페이지는 (웹 서비스가있을 때 경우를 고려 웹 서비스에서 데이터를 가져 오는 시작로드 응답을하지 않고 컨트롤이 부분을 잡으려고합니다.) 다시 말하면 뒤로 버튼을 누르거나 페이지를 탐색하면 새 페이지에서 메시지 상자가 나타납니다.
어떻게 그럴 수 있습니다.
감사합니다 감사합니다
이 솔루션도 사용할 수 있지만 바로 솔루션을 찾을 수 있습니다. – Mohit