How to make a synchronous service Call using HttpWebRequest (or) HttpClient in the C # / XAML Metro application?

advertisements

I am Developing a C#/Xaml Metro Application in that As per the Requirement I want to have a Synchronous service call , instead of ASynchronous Service Call.

This what I have used for Async Operation but I want to make a Synchronus Service Call :-

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://xxxxxxx");
    request.Method = "POST";
    request.Credentials = new NetworkCredential("xxx", "xxx");
     using (Stream requestStream = await request.GetRequestStreamAsync())
    {
    }

Please Let me know how can I Make a Synchronous service Call using HttpWebRequest or HttpClient in C#/XAML Metro App ????

Looking forward for your response.

Thanks in Advance.


I use this method because it allows for doing other work before waiting:

        var t = request.GetRequestStreamAsync();
        //do other work here
        t.Wait();
        using (Stream requestStream = t.Result)
        {
        }