locked
How do I build a front end webservice to connect my app to a local MySQL database?

    Question

  • I realise there are some posts on related topics but I haven't found them clear enough, and also I haven't seen one that refers to developing locally.

    I am just starting out and I'm trying to connect my app to a local MySQL database. For the app development I am using Vis Studio Express and Blend, for PHP/MySQL I have installed XAMPP. Now I realise that I have to create a "front-end web service", however this is something I had never heard of until now. What software, programming knowledge and tutorials would I need to learn how to do this? Is there an alternative solution e.g. downloading a pre-built web service?

    I have knowledge of HTML, CSS and some basic PHP. I am researching XML at the moment.

    Thanks in advance.


    EDIT: To clarify - the local database is being used ONLY for testing. I do not yet have a hosted or dedicated server, but once the app is functional and working locally I will obtain one. The final app will obviously not run from a local database.
    • Edited by Maracles Monday, November 12, 2012 8:41 AM
    Monday, November 12, 2012 8:14 AM

Answers

  • Hi,

    You could write the web service with php or asp.net. And then call the webservcie with winjs.xhr.

    Wjs.xhr example as follow:

    var feedItems = [];
    
    
        function loadBlogFeedsFromWebAsXML() {
    
            var feedUrl = "http://blogs.msdn.com/b/windowsstore/rss.aspx";
    
            WinJS.xhr({ url: feedUrl }).then(
            function (result) {
    
                var xmlDoc = new Windows.Data.Xml.Dom.XmlDocument();
                xmlDoc.loadXml(result.responseText);
    
                var nodes = xmlDoc.selectNodes("//item");
    
                var items = new Array();
    
                nodes.forEach(function (val, idx, travObj) {
    
                    var title = val.selectSingleNode("title").innerText;
                    var description = val.selectSingleNode("description").innerText;
                    var link = val.selectSingleNode("link").innerText;
    
                    var newItem = {
                        title: title,
                        summary: description,
                        uri: link
                    };
    
                    items.push(newItem);
                });
    
                DataUtils.feedItems = items;
    
    
                // Call other function which can use the DataUtils.feedItems to bind UI elements            
    
            },
            function (err) {
            }
            );
    
            return DataUtils.feedItems;
        }
    
    
    
    
    
        WinJS.Namespace.define(
            "DataUtils", {
                feedItems: feedItems
            }
            );


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework

    • Marked as answer by Song Tian Friday, November 16, 2012 9:07 AM
    Monday, November 12, 2012 9:13 AM
  • Hi,

    There are many tutorial how to create a webservice or wcf.

    For example: https://www.google.com/search?q=create+web+service&aq=1&oq=create+webser&sugexp=chrome,mod=18&sourceid=chrome&ie=UTF-8 .


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework

    • Marked as answer by Song Tian Friday, November 16, 2012 9:07 AM
    Tuesday, November 13, 2012 1:57 AM

All replies

  • Hi,

    You could write the web service with php or asp.net. And then call the webservcie with winjs.xhr.

    Wjs.xhr example as follow:

    var feedItems = [];
    
    
        function loadBlogFeedsFromWebAsXML() {
    
            var feedUrl = "http://blogs.msdn.com/b/windowsstore/rss.aspx";
    
            WinJS.xhr({ url: feedUrl }).then(
            function (result) {
    
                var xmlDoc = new Windows.Data.Xml.Dom.XmlDocument();
                xmlDoc.loadXml(result.responseText);
    
                var nodes = xmlDoc.selectNodes("//item");
    
                var items = new Array();
    
                nodes.forEach(function (val, idx, travObj) {
    
                    var title = val.selectSingleNode("title").innerText;
                    var description = val.selectSingleNode("description").innerText;
                    var link = val.selectSingleNode("link").innerText;
    
                    var newItem = {
                        title: title,
                        summary: description,
                        uri: link
                    };
    
                    items.push(newItem);
                });
    
                DataUtils.feedItems = items;
    
    
                // Call other function which can use the DataUtils.feedItems to bind UI elements            
    
            },
            function (err) {
            }
            );
    
            return DataUtils.feedItems;
        }
    
    
    
    
    
        WinJS.Namespace.define(
            "DataUtils", {
                feedItems: feedItems
            }
            );


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework

    • Marked as answer by Song Tian Friday, November 16, 2012 9:07 AM
    Monday, November 12, 2012 9:13 AM
  • Thank you for your response, I am trying to break this down now to understand how it works. However you said I use this 'after' I've written my web service. Writing the web service is the main part I need assistance with, I do not know how to write a web service or which resources or software I need and I cannot find many useful tutorials.

    Can you help me in this area?

    Thanks.

    UPDATE: I have used the following tutorial and have managed to connect to the local database (it would also work for hosted). I can't claim to understand everything that is going on but after having broken it apart line by line I understood it enough to get it working.


    • Edited by Maracles Monday, November 12, 2012 9:59 PM
    • Marked as answer by Maracles Monday, November 12, 2012 9:59 PM
    • Unmarked as answer by Song Tian Tuesday, November 13, 2012 5:09 AM
    Monday, November 12, 2012 7:59 PM
  • Hi,

    There are many tutorial how to create a webservice or wcf.

    For example: https://www.google.com/search?q=create+web+service&aq=1&oq=create+webser&sugexp=chrome,mod=18&sourceid=chrome&ie=UTF-8 .


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework

    • Marked as answer by Song Tian Friday, November 16, 2012 9:07 AM
    Tuesday, November 13, 2012 1:57 AM