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

Top 5 Contributors of the Month
Post New Web Links

null response when consume WCF REST API Using Jquery

Posted By:      Posted Date: September 17, 2010    Points: 0   Category :WCF
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?

View Complete Post

More Related Resource Links

host and consume wcf rest service in web project in single solution

I have  create a solution which have multiple class library project and a web application Like Web(UI),BL,DAL etc. I have also add a WCF REST starter kit Collection project in the same Solution.WCF Rest API is working fine if I host it on IIS but i want to consume this in my web project without using IIS. Is this possible? if yes then what will be the URI  for my WCF Rest services? Add service reference is also not working because WSDL is disable in rest.

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();

jquery runtime error: Microsoft JScript runtime error: 'nodeName' is null or not an object


Microsoft JScript runtime error: 'nodeName' is null or not an object

in jquery-1.4.2.min.js 

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



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/">

Best way to consume REST service


I've been using 'Add Service Reference' for years now to consume SOAP based services, not because I don't understand WCF, but because I don't have time to hand-roll contracts, classes, etc everytime I want to consume something.

Now I have to consume a REST service and 'Add Service Reference' can't handle.   It looks like I'm in a position where I'm going to have to hand-roll a bunch of contracts and classes in order to consume and that just bugs me to death.

Isn't there something in VS2008/10 that does this the way 'Add Service Reference' does for SOAP services?    If not I'm very disappoint with Microsoft - Visual Studio is suppose to be about RAD - hand rolling things just to consume isn't very RAD-like.

how to consume wcf 4.0 rest services in asp.net MVC



how to consume wcf rest services in asp.net MVC? there is any standards are available?

in my project SOA, so all the data came from wcf 4.0 rest services if there is any coding examples or resources to consume wcf services in MVC 2.0

JQuery & REST



On my masterpage I want to load some Events stored on my site.
I wanna do this using JQuery & Rest, I do the following:

var restStr = "../_vti_bin/listdata.svc/Events"

                restStr, null,
                function (data) {
                    $.each(data.d.results, function (i, result) {
                        eventList[i] = { Title: result.Title, StartDate: result.StartDate };

Everything goes fine, but when I want to get only the first 10 items and I add top=10.
Like this: 

var restStr = "../_vti_bin/listdata.svc/Events?$top=1"

I get an error from the jQueyr lib:

Webpage error details
Message: 'length' is null or not an object
Line: 29
Char: 452
Code: 0
URI: ############

Null reference in IE8 when using jquery to create cookie


Im trying to create a cookie:

if ($.cookie('locations') == null) {
    //cookie does not exist, just set cookie to empty
    alert('cookie empty');
    $.cookie('locations', '');
    //also tried $.cookie('locations', null);

This code works in FF, but in IE8 it throws an error:
Message: '$.cookie(...)' is null or not an object

So when ($.cookie('locations') == null), I first get an alert 'cookie empty' and then the error.
How can I get this to work?

Below my code for creating a cookie:

jQuery.cookie = function (name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        var expires = '';
        if (options.expir

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.

var sreg = response.GetExtension(); return null into mvc-3 application


my webconfig code is:

<?xml version="1.0"?>
  For more information on how to configure your ASP.NET application, please visit

    <section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true"/>
    <sectionGroup name="system.serviceModel">
      <section name="domainServices" type="System.ServiceModel.DomainServices.Hosting.DomainServicesSection, System.ServiceModel.DomainServices.Hosting, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" allowDefinition="MachineToApplication" requirePermission="false" />

          <!-- The following OPTIONAL behavior allows RPs to use SREG only, but be compatible
                    with OPs that use Attribute Exchange (in various formats). -->
          <add type="DotNetOpenAuth.OpenId.Behaviors.AXFetchAsSregTransform, DotNetOpenAuth" />
    <add name="ApplicationServices" connectionStri

GridView Confirmation Box Using JQuery BlockUI in asp.net

JQuery is the most popular JavaScript library. One of the main reasons for its fame is the plugin architecture. Anyone can create a separate library that leverage the JQuery library. In this article we are going to look at the BlockUI library which is used to block the user screen while performing a task.

jQuery $(document).ready() and ASP.NET Ajax asynchronous postback

Many call it the ASP.NET jQuery postback problem, but using the technique below should make it no problem anymore. $(document).ready() isn't called after an asynchronous postback. What this means? You lose the functionality that should be executed within $(document).ready() after an UpdatePanel rendered its contents after an asynchronous postback.

call JavaScript - jQuery code from ASP.NET Server-Side

jQuery got so close to me lately that I can see myself adding the scripts to my project almost unconsciously. The thing is, jQuery is very useful for me, in almost all situations and it has been a do or die enhancement for all my project since I first put my hands on it.

Of course while using it, you encounter few situations which need a bit of research to solve, mostly when you are trying to combine it with some other technologies like: UpdatePanels and ASP.NET Ajax. For instance there are many situations when I would like to run some jQuery magic based on some decision that I make on the server side.

Making Ajax Callbacks to the Server Using jQuery with ASP.NET

In the first part of this article series I introduced jQuery's functionality and how it provides a rich client side programming model. This time around I'll expand on these concepts and show you how you can use jQuery in combination with ASP.NET using it as an AJAX backend to retrieve data. I'll also discuss how you can create ASP.NET controls and otherwise interact with jQuery content from ASP.NET pages in WebForms.

jQuery is just a JavaScript library so it will work seamlessly with ASP.NET both from page code as well as through backend driven code using the Page.ClientScript object or ScriptManager. You can use jQuery on its own as a client side and Ajax library that communicates with ASP.NET or you can use jQuery in combination with ASP.NET AJAX. The two actually complement each other quite well as jQuery provides functionality that the ASP.NET AJAX library does not and vice versa. For the most part the interaction between the two libraries is trouble free except for a few very rare edge cases.

Displaying Row Details Tooltip on GridView using JQuery

Continuing exploring JQuery! I decided to implement a feature to display some kind of details related to a row displayed on GridView. For example when displaying employees details on GridView some information might not fit in the GridView because it will make it huge and wide. These infomration can be diplayed as Tooltip. Or when you want to display a picture and some kind of formated text to be diplayed as tooltip when mouse hover on the image.

jQuery: Highlight Gridview Rows with Checkbox

Im learning and experimenting with jQuery and ASP.NET. Below is a simple solution I created to highlight rows in a gridview by clicking on a checkbox next to the row.

Gridview setup:

Using jQuery with ASP .NET

With that, JQuery is officially embraced by ASP.NET.

A brief introduction of JQuery

jQuery is the star among the growing list of JavaScript libraries. A few of its characteristics are light-weight, cross-browser compatibility and simplicity. A common task that sometimes takes 10 lines of code with traditional JavaScript can be accomplished with jQuery in just one line of code. For example, if you want to dress up a table with an ID mytable with alternative color for every other row, you can simple do this in jQuery.
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