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 7903117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:39:58+00:00 2026-06-03T09:39:58+00:00

I am making a request to a service and getting a response. Service works

  • 0

I am making a request to a service and getting a response. Service works fine and I am deserializing an object without a problem.

Below is an example of my code. The problem is the result object is null at the end. I do not know why am I losing a reference. What is the proper solution?

        HttpWebRequest hwrq = (HttpWebRequest)WebRequest.Create("http://service.svc/Login");
        hwrq.ContentType = "application/x-www-form-urlencoded; encoding='utf-8'";
        hwrq.Accept = "text/xml";
        hwrq.Method = "POST";

        Users result = null; // object initializaiton

        hwrq.BeginGetRequestStream(ar =>
        {
            var requestStream = hwrq.EndGetRequestStream(ar);
            using (var sw = new StreamWriter(requestStream, System.Text.Encoding.UTF8))
            {
                sw.Write("Username Password");
                sw.Close();
            }

            hwrq.BeginGetResponse(a =>
            {
                var response = hwrq.EndGetResponse(a);
                var responseStream = response.GetResponseStream();
                using (var sr = new StreamReader(responseStream))
                {
                    returnedXML = sr.ReadToEnd();

                    XmlSerializer xds = new XmlSerializer(typeof(Users));

                    byte[] byteArray = Encoding.UTF8.GetBytes(returnedXML);
                    MemoryStream stream = new MemoryStream(byteArray);

                    result = (Users)xds.Deserialize(stream); // object is correct
                }
                responseStream.Close();
                response.Close();
            }, null);
        }, null);

        return result; // object is null!
  • 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-03T09:39:59+00:00Added an answer on June 3, 2026 at 9:39 am

    Just like MarcinJuraszek suggested, the proper way is to make a callback and handle the results there.

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

Sidebar

Related Questions

Making a request to a RESTful service in Silverlight with HttpWebRequest works well so
I am making a request to a CGI program using AJAX. The response sends
I have the following code making a GET request on a URL: $('#searchButton').click(function() {
I'm making a request to the google closure compiler API service: $content = file_get_contents('file.js');
I am making request to web service and have to do this extending AsyncTask
In SOAP-UI I am making a request to a web service like this: <soapenv:Envelope
I'm working on a web service and I need a code for making an
I am making a synchronous request to the web service and unable to show
I'm making a request from an UpdatePanel that takes more then 90 seconds. I'm
I'm looping through a list of dates and making a request to a web

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.