I'm porting some code from the full .NET framework to the WP7 version and I'm running into an issue with synchronous vs async calls.
string response;
string requestString = GenerateReqString();
HttpWebRequest req = (HttpWebRequest) WebRequest.Create("endpoint");
req.Method = "POST";
req.ContentType = "text/xml";
req.ContentLength = requestString.Length;
StreamWriter sw = new StreamWriter (req.GetRequestStream(), System.Text.Encoding.ASCII);
sw.Write(requestString);
sw.Close();
StreamReader sr = new StreamReader(req.GetResponse().GetResponseStream());
response = sr.ReadToEnd();
sr.Close();
The response string is then parsed into a list of objects that is returned by the method.
The problem I'm having is that there isn't a way to make the call synchronously in Silverlight/WP7. If I use a call back I'll get the response in a different function and wont be able to return it from the original function. Is there a way to either make the call synchronously or return from the CallBack function back to the method that kicked off the async call?