.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

What is the best way to read REST (XML) response?

Posted By:      Posted Date: October 01, 2010    Points: 0   Category :ASP.Net


I make a REST request to Amazon S3 using HttpWebRequest and get an XML response. The simplest example is my bucket list. I want to display the number of buckets and their names. What is the most efficient way to read the XML response and process it?

This is the XML response I'm getting:

<ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">

View Complete Post

More Related Resource Links

Can't read MTOM response

Hi Guys, I am running into a problem when trying to call a service that uses MTOM encoding.  Basically, I make the call and an error is thrown: "Client found response content type of 'multipart/related; type="application/xop+xml"; start="<soap.xml@xfire.codehaus.org> "; start-info="text/xml";               boundary="----=_Part_413761_448939451.1284410234193"', but expected 'text/xml'." Since my app is defaulted to text/xml I change my config using the WSE tool so that it will be able to accept MTOM responses, however trying the call again continues to throw that same error.  Here is my config: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="microsoft.web.services3" type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration, Microsoft.Web.Services3, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </configSections> <applicationSettings /> <system.web> <globalization /> <webServices> <soapExtensionImporterTypes> <add type="Microsoft.Web.Services3.Description.WseExtensionImporter, Microsoft.Web.Services3, Version=, Culture=neutral, PublicKeyTo

null response when consume WCF REST API Using Jquery

I have created and hosted my WCF REST API Using WCF REST Starter Kit preview2. Which supports Dynamic Response and Request format type (XML and JSON).Everything is working fine if I consume the service through fiddler or Microsoft.Http and Microsoft.Http.Extensions on cs side. My cs code is as following: private void GetData() { string url = string.Format("http://myhost/Services/UserService.svc/people/"); HttpClient client = new HttpClient(); HttpResponseMessage responseMessage = client.Get(url); responseMessage.EnsureStatusIsSuccessful(); using (responseMessage) { string res = responseMessage.Content.ReadAsString(); Response.Write(res); } } now when I try to consume my service using Jquery Response is comming in IE8 but in Mozilla and Chrome I am getting null response My jquery code is as following : function loadData() { var path = "http://myhost/Services/UserService.svc/people/"; $.ajax({ type: "GET", url: path, contentType: "application/json; charset=utf-8", dataType: "json", async: false, success: function(response) { if (response != null) { displayData(response); } } }); } I am using visual studio 2008. I have also check jqeury call in firebug status shows 200 OK. can anyone help me?

REST Web service,not getting response


Hi ,

I have to call a REST web service method that is deployed remotely on a machine and i use VPN to connect through that url. It works fine when i use the browser to view the output of the web service method but i am unable to get the response in the code as i get an exception. The response status message is OK but when i try to read the response content from the streamreader i get the exception "ex = {"Unable to read data from the transport connection: The connection was closed."}". The content length is -1 in the HttpWebReponse object. Here is the code

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("");

        //apply this url when working with the software
       // HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost:1901/metascan_rest/scanner?method=getengineinfo");
        request.Method = "GET";
        WebResponse res = request.GetResponse();

        string status = ((HttpWebResponse)res).StatusDescription;

        Stream stream = res.GetResponseStream();
        StreamReader reader = new StreamReader(stream);

          //this is where the exception occurs
            string output = reader.ReadToEnd();

How to read web.config params in WCF 3.5 with REST using JSON


Hi Carlos,

I've a web site project on top of which I've created my REST service by creating a New Project -> New Web Site instead of WCF Service. The reason I did this is because I wanted to use some config params from original web site's web.config

Is there any way to read the web site's web.config if I chose the option New Wcf Service?


Response.TransmitFile stops rest of page execution



i am trying to have a download on my page. I have implemented the code below but code execution stops after the download message pops up, even if i press save or cancel, nothing happens after that.

            Response.AddHeader("Content-Disposition", "attachment; filename=" + lFile.Name);
            Response.AddHeader("Content-Length", lFile.Length.ToString());
            Response.ContentType = "application/octet-stream";

I have tried it a few times without Response.Clear() and Response.End() but it didn't make any difference to take these off. Is there anyway I can achieve this without having to using an IFrame?

Any suggestions will be very much appreciated.

Can't read ping response from webservice

I am trying to ping a webservice but the response is coming back= nothing
I contacted a person there and he said they were receiving the ping and sending back a
success response as shown after my code.
I am unable to read the rsponse. Any help is appreciated 
Protected Sub btnPing_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPing.Click
        Dim ES As New EchoSignDocumentService()
        Dim serviceurl As String = "https://www.echosign.com/services/EchoSignDocumentService9"
        ES.Url = serviceurl
        Dim s As String
        Dim apikey As String = "XDYYBE6Y336S3F"
        s = ES.testPing(apikey).message
    End Sub

Also tried

  Protected Sub btnPing_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPing.Click
        Dim ES As New EchoSignDocumentService()
        Dim serviceurl As String = "https://www.echosign.com/services/EchoSignDocumentService9"
        ES.Url = serviceurl
        Dim pong As Pong
        Dim apikey As String = "XDYYBE6Y336S3F"
        pong = ES.testPin

How to read XML response com from another site such as Mooneybookers or CashU?


hi everybody; this is the first time I post help request

In my system I submitting html form to payment site (Moneybookers or CashU), the the site response me by XML response to tell me the status of the payment proces.

I want to read this XML response in the page which will recieve this response.

the XML response like the folowing:

<date>14/09/2007 23:07</date>
<date>14/09/2007 23:07</date>
<paymentCurrency> </paymentCurrency>


_AppStart.cshtml: can't get response/request to write/read cookie?


currently, I'm setting up an HttpCookie in a "master" page (layout) and check wiehter I need to send the user back to some specific page depending on the value, if it has expired, etc.
Because the master layout page is not the 1st "page" code to process, I can sometime get runtime error because the cookie is already expired.

I thought I would move this part to the _AppStart.cshtml file but I can't get to read/write (Response/Request) the cookie there?

Should I do this in a _PageStart.cshtml in all my folders rather?


Serial Port Communication Read and Write using C#.net

In this simple article you will learn that how you can Open and read COM port data using System.IO.Ports Namespace.
Simply just create New Project of windows application in C#.

Import ServiceProcess APIs
using System.IO.Ports

Imports System.IO.Ports

Write Parsing functions which parse port data according to attached device

Response.BinaryWrite help needed


Hi all

Im new to .NET and stuck now, so i hope anyone can help my with my problem.

I have a MS SQL database where i have stored some documents as Binary data. I cant figure out how to retrieve them and show/download them in my browser.

I found some guides online and have try to put something together.


private void Write()
 int id = 0;
 string strID = Request.QueryString["id"];
 int.TryParse(strID, out id);

 var db = new ModelDataContext();
 var doc = db.DocumentDatas.Where(x => x.ID == id).FirstOrDefault();

 byte[] byteArray = File.ReadAllBytes(doc);


How do i fill the byteArray with the data?

Thanks in advance :)


Response.Redirect slow


I'm in the middle of migrating servers and on the new server Response.Redirect is extremely slow. It takes around 20 seconds for the browser to get the redirect. This is something that was quick on the existing server. It's an ASP.NET 2.0 application, both servers are running IIS6.

Additionally, if I "manually" do the redirect, it's fast. For example:

Existing way:


takes around 20 seconds on the new server

New way:

Response.Status = "302 Moved Temporarily";
Response.AddHeader("Location", url);

is fast on the new server.

Any ideas why Response.Redirect would be so slow on the new server?

Scripts not read when in head tag


I just upgraded to VS2010 if that matters.  I'm learning JQuery and noticed that scripts don't work if they're in the head tag.  Also, I need the script tag with type="text/javascript" in the head (with nothing else) in order for the JQuery scripts in the body to work.

Very bizzare, any suggestions?

With a separate script tag in the <body> with my JQuery script, this works

<head runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" />
<script type="text/javascript">

This doesn't:

<head runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" />

I am not able to read xml file with XDocument if its Descendants has Attribute xmlns="http://abc.co


I am not able to read xml file with XDocument if its Descendants has  Attribute like:-

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
  <row ID="1" xmlns="http://www.opentravela.org/OTA/2003/05">
    <var country_name="Caribbean and Rest of the world" city_name="Kingston" flight_category="Economy Class" via="Atlanta" flight_departure="London Heathrow" airline_logo="Delta" adult_fare="Delta" child_fare="660" infant_fare="561" date1="132" date2="2010-08-15" />


I don't know what to do ?

Looking for some help..

How to read XML using LINQ in VB.NET


Can someone please tell me (sample code) how to read this XML into a SQL DB?  Should I use LINQ to XML?  Does anyone have any sample code?  I am working in VB.NET


<?xml version="1.0" encoding="utf-8"?>

<ReadOrderResponseType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<Status xmlns="urn:mysol:apis">Success</Status>

<TimeStamp xmlns="urn:mysol:apis">2010-07-25T15:26:49.1150235Z</TimeStamp>

<StoreUrl xmlns="urn:mysol:apis">http://xyz.COM</StoreUrl>

<PageResponse xmlns="urn:mysol:apis">




Read Excel file from Web Application (C#)



I have a web app where user uploads a file.

File is saved in server locally and I want to read some data from it.

Currently my development  server has office 2003.

So do I need office 2007 in order to be able to  read an excel from office 2007 ?

What are other requirements  ?

I tried a test, using

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wrkBook; // = new Microsoft.Office.Interop.Excel.Workbook();

wrkBook = excelApp.Workbooks.Open(@"C:\www\excel_files\b.xls", ....);

But When trying to open the file I get the error:

Exception from HRESULT: 0x800A03EC

So I'm wondering what I'm missing.


How to read value of CheckBox in EXCEL sheet


I am using OLEDBConnection (@"Provider=Microsoft.ACE.OLEDB.12.0;") to connect to the EXCEL file and read contents. When I read the contents, I get all the contents from the excel sheet but i dont get contents for checkboxes placed inside.

My Excel sheet contains set of checkboxes and I need to know If they are checked or not.These checkboxes are controls which are added from Developer tab in EXCEL.

I dont want to use Excel Assemblies for reading contents as it is not recommended. And also i am using OLEDBconnection and want to stick to this .

Awaiting replies from you guys. Thanks in Advance.

How to read Excel table?


If I  use Microsoft.Jet.OLEDB.4.0 to retreive for example named range or sheet from Excel and use it as data source for some server control on the ASP page, everything works fine. But when I try to get table from Excel like this: "select * from [Table1]", debugger complains that database engine could not find object Table1. So how should I reference Table1 in Excel file so that the database engine could find it?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend