locked
PopFly and ADO.Net Data Services

    Question

  • Hi Guys,

     

    There seems to be little support for ADO.Net Data Services in Popfly will this change in later versions?  It would be really neat to be able to create a RESTFul ADO.Net Data Services data source in popfly...

     

    I'm working around this limitation and trying to use the codeplex ASP.Net 3.5 ADO.Net Data services library with popfly reusing an existing Northwind data source on the web.  When I try and execute "var serviceUri = new Sys.Data.DataService(http://www.thedatafarm.com/dataservices/northwind/awdataservice.svc)" I get an null message exception.

     

    Code Snippet

    /// <reference path="DataService.debug.js" />

     

    //declare/define the class

    function NorthwindClass() {

    }

    //define the getCustomers function in the class

    NorthwindClass.prototype.getCustomers = function(callback) {

    debugger;

    var queryString = "Customers?$top=40" + "$expand=Orders";

    var serviceUri = new Sys.Data.DataService(http://www.thedatafarm.com/dataservices/northwind/awdataservice.svc);

    serviceUri.query(queryString, function(result)

    {

    var count = result.Count;

    var custArray = new Array();

     

     

    callback(custArray);

    });

     

     

     

    Thanks

     

    John

    Tuesday, July 08, 2008 9:29 PM

All replies

  • Hi,

    One of the blocks (and more to come!) use the ADO.net data services, the block "DC Crime Stats" has code that looks like:

    Code Snippet


    function CrimeStatsDCClass() {
    this.dataUrl = "http://data.popflycreator.com/CrimeStats.svc/ReportedCrime";
    }

    CrimeStatsDCClass.prototype.getRecentCrimes = function CrimeStatsDCClass$getRecentCrimes(numCrimes) {
    var jsonText = environment.getHttpResponse(this.dataUrl + "?$top=" + numCrimes + "&$orderby=ReportDateTime%20desc", null, [{ "Key": "Accept", "Value": "application/json"}], null);
    var response = (eval("(" + jsonText.responseText + ")")).d;

    return this.parseResponse(response);
    };


    CrimeStatsDCClass.prototype.parseResponse = function CrimeStatsDCClass$parseResponse(response) {
    var results = []
    var currentResult = {}
    for (var i in response) {
    currentResult = new ReportedCrime( response[i]["nid"],
    response[i]["ReportDateTime"],
    response[i]["Offense"],
    response[i]["Method"],
    response[i]["BlockSiteAddress"],
    response[i]["Narrative"],
    response[i]["Latitude"],
    response[i]["Longitude"],
    response[i]["City"],
    response[i]["district"] );
    results.push(currentResult);
    }

    //For a nice preview, we need each object to have a good preview - so we add
    // a toString method for all of them
    for (var i = 0; i < results.length; i++) {

    results[i].toString = function() {
    var output = "<p>";
    for (var field in this) {
    if (field == "toString") {
    continue; //Don't show output for this function!
    }
    output += field + " : " + this[field] + " <br/>";
    }
    output += "</p>";
    return output;
    };

    }

    return results;
    };

    function ReportedCrime(nid, reportDate, offense, method, blockSiteAddress, narrative, latitude, longitude, city, district)
    {
    this.nid = nid;
    this.reportDate = reportDate;
    this.offense = offense;
    this.method = method;
    this.blockSiteAddress = blockSiteAddress;
    this.narrative = narrative;
    this.latitude = latitude;
    this.longitude = longitude;
    this.city = city;
    this.district = district;
    this.iconUrl = ReportedCrime.icons[offense];
    };

    ReportedCrime.icons = { "ADW":"/Content/Components/Resources/CrimeStatsDC/ADW.png",
    "HOMICIDE":"/Content/Components/Resources/CrimeStatsDC/HOMICIDE.png",
    "BURGLARY":"/Content/Components/Resources/CrimeStatsDC/BURGLARY.png",
    "ROBBERY":"/Content/Components/Resources/CrimeStatsDC/THEFT.png",
    "SEX ABUSE":"/Content/Components/Resources/CrimeStatsDC/SEX ABUSE.png",
    "STOLEN AUTO":"/Content/Components/Resources/CrimeStatsDC/STOLEN AUTO.png",
    "THEFT F/AUTO":"/Content/Components/Resources/CrimeStatsDC/THEFT.png",
    "THEFT":"/Content/Components/Resources/CrimeStatsDC/THEFT.png" };


    ReportedCrime.prototype.toString = function()
    {
    var html = "<div>";
    html += "<strong>"+this.offense+"</strong> at "+ this.blockSiteAddress + " ( "+this.latitude+", "+this.longitude+" ), reported at "+this.reportDate;
    html += "<p>"+this.narrative+"</p>";
    html += "</div>";
    return html;
    };




    In this case we're actually hosting the service as well but it could be anywhere so long as you go through our proxy (By using environment.getXml)
    Friday, July 11, 2008 11:14 PM
    Owner