Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:57:52+00:00 2026-06-15T22:57:52+00:00

I’m trying to write a library for Windows Phone 8 and would like to

  • 0

I’m trying to write a library for Windows Phone 8 and would like to know if its possible to consume JSON without using callbacks by using the await keyword? Or am I mistaken on how this works?

Essentially I want the app to be able to say:

string result = Library.Ping(var1, var2);

The library connects to the web service and deserializes the content from JSON to a dynamic object. Then it returns it to the main app that had sent the request to the library.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:57:53+00:00Added an answer on June 15, 2026 at 10:57 pm

    See for linked answer in case the website goes down:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Threading.Tasks;
    using System.ComponentModel;
    
    namespace Win8WinPhone.CodeShare.Extensions
    {
        public static class HttpExtensions
        {
            public static Task<Stream> GetRequestStreamAsync(this HttpWebRequest request)
            {
                var taskComplete = new TaskCompletionSource<Stream>();
                request.BeginGetRequestStream(ar =>
                {
                    Stream requestStream = request.EndGetRequestStream(ar);
                    taskComplete.TrySetResult(requestStream);
                }, request);
                return taskComplete.Task;
            }
    
            public static Task<HttpWebResponse> GetResponseAsync(this HttpWebRequest request)
            {
                var taskComplete = new TaskCompletionSource<HttpWebResponse>();
                request.BeginGetResponse(asyncResponse =>
                {
                    try
                    {
                        HttpWebRequest responseRequest = (HttpWebRequest)asyncResponse.AsyncState;
                        HttpWebResponse someResponse = (HttpWebResponse)responseRequest.EndGetResponse(asyncResponse);
                        taskComplete.TrySetResult(someResponse);
                    }
                    catch (WebException webExc)
                    {
                        HttpWebResponse failedResponse = (HttpWebResponse)webExc.Response;
                        taskComplete.TrySetResult(failedResponse);
                    }
                }, request);
                return taskComplete.Task;
            }
        }
    
        public static class HttpMethod
        {
            public static string Head { get{return "HEAD";} }
            public static string Post { get{return "POST";} }
            public static string Put { get{return "PUT";} }
            public static string Get { get{return "GET";} }
            public static string Delete { get{return "DELETE";} }
            public static string Trace { get{return "TRACE";} }
            public static string Options { get{return "OPTIONS";} }
            public static string Connect { get{return "CONNECT";} }
            public static string Patch { get{return "PATCH";} }
        }
    
    }
    

    Then you can write your function as:

    public async Task<string> GetMyData(string urlToCall) 
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlToCall);
        request.Method = HttpMethod.Get;
        HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();
        using (var sr = new StreamReader(response.GetResponseStream())) 
        { 
            return sr.ReadToEnd(); 
        } 
    }
    

    And then call it as:

    Tweet myTweet = await GetTweet(tweetID);
    

    All credit goes to:
    @robertftw who linked to: http://www.windowsphonegeek.com/news/windows-8—windows-phone-code-sharing-httpwebrequest-getresponseasync

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
I am using jsonparser to parse data and images obtained from json response. When
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.