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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:33:21+00:00 2026-06-17T09:33:21+00:00

This is my code in MVC: string url = https://api….; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

  • 0

This is my code in MVC:

    string url = "https://api....";
    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    httpWebRequest.Method = "POST";
    httpWebRequest.ContentType = "application/x-www-form-urlencoded";

    string postData = "<?xml version=\"1.0\"?>" +
                        "<request>" +
                            "<login>" + Login + "</login>" +
                            "<password>" + Password + "</password>" +
                            "<limit>" +
                                "<offset>10</offset>" +
                                "<limit>10</limit>" +
                            "</limit>" +
                        "</request>";

    try
    {
        using (StreamWriter requestWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            requestWriter.Write(postData);
        }
    }
    catch (System.Net.WebException ex)
    {
        return null;
    }

    HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    Stream responseStream = httpWebResponse.GetResponseStream();
    StreamReader streamReader = new StreamReader(responseStream);
    var serializer = new System.Xml.Serialization.XmlSerializer(typeof(Class.hotels));
    Class.hotels hotel = (Class.hotels)serializer.Deserialize(streamReader);
    streamReader.Close();
    responseStream.Close();
    httpWebResponse.Close();

I got same functionality in my Windows Phone 7 project (little changes with asynchronous calling) and it’s working. I have added classes from WP7 project to MVC and I am trying now in MVC. Everything is working but in final I got hotel with 0 items (but in WP I got items in there). I tried to read streamReader to string and I got there right answer so the problem must be with deserializing.

So what could be problem? If class would be wrong I get error message from XmlSerializer, am I right (and in WP it wouldn’t be working too)? But I don’t know where else could be the problem. Thanks for help

Edit:
Part of hotels class:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.17929")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
public partial class hotels : object
{
    private int countfield;
    private ObservableCollection<hotel> hotelfield;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
    public int count
    {
        get
        {
            return this.countfield;
        }
        set
        {
            this.countfield = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
    public ObservableCollection<hotel> hotel
    {
        get
        {
            return this.hotelfield;
        }
        set
        {
            this.hotelfield = value;
        }
    }

}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.17929")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
public partial class hotel : object, System.ComponentModel.INotifyPropertyChanged
{

    private int hotIdField;

    private int hoyIdField;
    ...
    many properties
    ...

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
    public int hotId
    {
        get
        {
            return this.hotIdField;
        }
        set
        {
            this.hotIdField = value;
            this.RaisePropertyChanged("hotId");
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
    public int hoyId
    {
        get
        {
            return this.hoyIdField;
        }
        set
        {
            this.hoyIdField = value;
            this.RaisePropertyChanged("hoyId");
        }
    }
    ...
    many getters, setters
    ...

and content of response (xml in string):

"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hotels>\n    <foundHotels>4655</foundHotels>\n    <hotel>\n        <hotId>12</hotId>\n        <hoyId>1</hoyId>\n        <bookOnline>0</bookOnline>\n        <name>OÁZA Říčany</name>\n        <address>\n            <couId>1</couId>\n            <regId>3</regId>\n            <cotId>51</cotId>\n            <towId>121</towId>\n            <zipId>12093</zipId>\n            <name>OÁZA Říčany</name>\n            <street>V Chobotě 2112</street>\n            <city>Říčany</city>\n            <zip>25101</zip>\n            <country>Česká republika</country>\n            <phone>\n                <number>+420 323 601 170</number>\n                <number>+420 736 679 097</number>\n                <number>724 165 420</number>\n            </phone>\n   ... many properties ...     </hotel>\n    <hotel>\n        <hotId>13</hotId>\n        <hoyId>1</hoyId>\n        <bookOnline>0</bookOnline>\n        <name>Hotel Maxov</name>\n        <address>\n            <couId>1</couId>\n            <regId>14</regId>\n            <cotId>20</cotId>\n            <towId>1317</towId>\n            <zipId>2492</zipId>\n            <name>Hotel Maxov</name>\n            <street>Dolní Maxov 710</street>\n            <city>Josefův Důl</city>\n            <zip>46844</zip>\n            <country>Česká republika</country>\n            <phone>\n                <number>483381085,483381100</number>\n            </phone>\n     ... many properties of another hotel ...        </hotel>\n</hotels>\n"
  • 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-17T09:33:22+00:00Added an answer on June 17, 2026 at 9:33 am

    Try redefining your classes like this:

    public partial class hotels : object
    {
        private int countfield;
        private ObservableCollection<hotel> hotelfield;
    
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order = 0, ElementName="foundHotels")]
        public int count
        {
            get
            {
                return this.countfield;
            }
            set
            {
                this.countfield = value;
            }
        }
    
        /// <remarks/>
        [System.Xml.Serialization.XmlElement(Order = 1,ElementName="hotel")]
        public ObservableCollection<hotel> hotel
        {
            get
            {
                return this.hotelfield;
            }
            set
            {
                this.hotelfield = value;
            }
        }
        // other fields
    }
    
    public partial class hotel : object, System.ComponentModel.INotifyPropertyChanged
    {
        private int hotIdField;
        private int hoyIdField;
    
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order = 0)]
        public int hotId
        {
            get
            {
                return this.hotIdField;
            }
            set
            {
                this.hotIdField = value;
                this.RaisePropertyChanged("hotId");
            }
        }
    
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute(Order = 1)]
        public int hoyId
        {
            get
            {
                return this.hoyIdField;
            }
            set
            {
                this.hoyIdField = value;
                this.RaisePropertyChanged("hoyId");
            }
        }
    
        // other properties
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making this ajax call: $.ajax({ url: /test/whatever, type: 'post', contentType: 'application/json' data:
I am using ASP.net MVC with C#. Why this is code: public IQueryable<Product> ListProducts(string
I'm trying to create a sitemap in an ASP.NET MVC project. This code in
This is my code: import play.api.mvc._ import play.api.libs.json._ import play.api.libs.json.Json._ import play.api.libs.json.Writes._ class BaseController
I have this code in a JavaScript function: var url = '@Url.Action(MVC.Membership.User.ActionNames.Update, MVC.Membership.User.Name)'; url
I have this code in mvc 3 razor @using (Html.BeginForm(MyAction, MyController)) { <input type=text
I use this code which is taken from MVC futures and attach the Attribute
This piece of code used to work in MVC 1 but it does not
This is a beginner level question for asp.net MVC I have the following code
Considering this article Developing a MVC component for Joomla , following is the code

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.