How to call a restfull service in windows app RRS feed

  • Question

  • Hi,

    Can anyone help me in calling a restfull service in windows app using WinJS.xhr or any other way.

    i am doing in the below, but getting an error by saying response code is '0'.

    function callback(responseText, status) {
        if (status === 200) {
            var feed = JSON.parse(responseText);
            for (var i = 0, len = feed.channel.length; i < len; i++) {
                var item = feed.channel[i];
                output('<a href="' + item.link + '" target="_blank">' + item.title + "</a><br/><br/>");
        } else {
            output("Error obtaining feed. XHR status code: " + status);
    var options = {
        url: 'http://localhost:6768/Rest/Service/SayHello',
        type: 'GET',
        responseType: 'json'
        function (result) {
            callback(result.responseText, result.status);
        function (result) {
            callback(null, result.status);
    function output(s) {
        document.getElementById("content").innerHTML += s;

    service returns  string value 'Hello'.

    Please help me..


    Thursday, September 11, 2014 10:06 AM


All replies

  • There are lots of tutorials on the web (e.g.: http://brandonlive.com/2014/01/28/building-great-winapps-your-first-winjs-app-part-1/).

    You might want to format your code a little bit (use the tools this forum offers..). Also response or status codes happen on a pretty early level of your request. If you're not even getting a 404 or anything common chances are that your service is misconfigured. 

    Did you double check the url? Maybe you should try this

        url: "https://localhost/yourservice",
    }).then(function (response) {
                    try {
                    var result = JSON.parse(response.responseText);

    with no options at first and see if you are getting a response.



    Friday, September 12, 2014 12:47 AM
  • See the documentation at Connecting to web services (HTML) . The HttpClient class is preferred to WinJS.xhr on current OSes.

    Loopback connections to localhost are not supported for general use and are disabled by default except when debugging.

    Friday, September 12, 2014 7:41 AM
  • Hi Fred,

    I have tried as suggested by you. Control is moving to 'terminateAppHandler()' function in base.js and the data.stack is null. status is '0'. responseText is empty.

    Pls help me!


    Thursday, September 18, 2014 3:59 AM
  • You will need to look at a successful call to the service and then compare it to your code.

    Here is an article that will help you in general troubleshoot HTTP problems:

          Troubleshooting code that uses the HTTP protocol



    Jeff Sanders (MSFT)

    @jsandersrocks - Windows Store Developer Solutions @WSDevSol
    Getting Started With Windows Azure Mobile Services development? Click here
    Getting Started With Windows Phone or Store app development? Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

    Thursday, September 18, 2014 7:24 PM